【问题标题】:Installing PyQuery Via Pip通过 Pip 安装 PyQuery
【发布时间】:2014-01-31 20:44:35
【问题描述】:

我正在尝试通过pip 安装PyQuery,但我遇到了一个我不明白的错误。我使用的命令是:

sudo pip install pyquery

我得到以下输出:

Requirement already satisfied (use --upgrade to upgrade): pyquery in /usr/local/lib/python2.7/dist-packages
Downloading/unpacking lxml>=2.1 (from pyquery)
Running setup.py egg_info for package lxml
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
  warnings.warn(msg)
Building lxml version 3.3.0.
Building without Cython.
ERROR: /bin/sh: 1: xslt-config: not found

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt

Downloading/unpacking cssselect (from pyquery)
Running setup.py egg_info for package cssselect

no previously-included directories found matching 'docs/_build'
Installing collected packages: lxml, cssselect
Running setup.py install for lxml
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
  warnings.warn(msg)
Building lxml version 3.3.0.
Building without Cython.
ERROR: /bin/sh: 1: xslt-config: not found

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/home/imageek/scripts/facebook/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:16:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/imageek/scripts/facebook/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-dyUZWZ-record/install-record.txt:
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'

warnings.warn(msg)

Building lxml version 3.3.0.

Building without Cython.

ERROR: /bin/sh: 1: xslt-config: not found



** make sure the development packages of libxml2 and libxslt are installed **



Using build configuration of libxslt

running install

running build

running build_py

copying src/lxml/includes/lxml-version.h -> build/lib.linux-i686-2.7/lxml/includes

running build_ext

building 'lxml.etree' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/home/imageek/scripts/facebook/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w

src/lxml/lxml.etree.c:16:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/home/imageek/scripts/facebook/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-dyUZWZ-record/install-record.txt failed with error code 1
Storing complete log in /home/imageek/.pip/pip.log

我感觉这与依赖关系有关,但是 'pip' 不应该自动安装依赖关系吗?

【问题讨论】:

  • 在包中正确设置依赖项的情况下这样做。
  • 这是我的python版本的问题吗?我相信是 2.6。
  • 您的计算机安装了 2.7,请检查 /usr/lib/python2.7 作为命运
  • 查看此消息“**确保已安装libxml2和libxslt的开发包**”
  • 我在 2.7 中尝试过,它也不起作用,输出中有很多错误

标签: python pip pyquery


【解决方案1】:

您缺少依赖项。尝试运行:

sudo apt-get install libxml2-dev libxslt1-dev python-dev

【讨论】:

  • 你怎么知道它需要什么库?
  • 这也解决了我的问题! @Torra 解决了你的问题吗?
【解决方案2】:

将以下行放入名为pyquery.sh 的文件中

#ADD SWAP FOR lxml COMPILATION
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

#ACTIVATE ENV
#Comment following line if you don't use virtualenv
#source /home/py3/bin/activate

#INSTALL ALL DEP
add-apt-repository -y ppa:ubuntu-toolchain-r/test
apt-get -y update
apt-get -y install gcc
apt-get -y install g++
apt-get -y install build-essential
apt-get -y install python-dev
apt-get -y install libxml2-dev
apt-get -y install libxslt-dev
apt-get -y install libxslt1-dev
apt-get -y install zlib1g-dev
apt-get -y install python3-setuptools
apt-get -y install python3-lxml
apt-get -y install python3-lxml-dbg
apt-get -y install python3-dev

pip install lxml
pip install pyquery

#REMOVE SWAP
swapoff /swapfile
rm -rf /swapfile

在此之后运行此文件:

source pyquery.sh

【讨论】:

  • 就我而言,我只是尝试安装lxml 并遇到了同样的错误。我删除了存储库版本的python-lxml2.3.2-1ubuntu0.2,然后再次尝试。没什么区别,gcc 问题仍然存在。 (我怀疑它会,我只需要确认。)
  • 现在我已经添加了完整的脚本
猜你喜欢
  • 1970-01-01
  • 2014-04-26
  • 2019-02-24
  • 2023-01-03
  • 2021-05-27
  • 2020-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多