如何使用 pip 安装特定版本的包

How to install a specific version of a package with pip

我想安装 Pyquery 1.2.4 版本,但是当我尝试

 pip install pyquery==1.2.4

我面对

  Compile failed: command 'gcc' failed with exit status 1
    creating tmp
    cc -I/usr/include/libxml2 -c /tmp/xmlXPathInitXZJM6c.c -o tmp/xmlXPathInitXZJM6c.o
    /tmp/xmlXPathInitXZJM6c.c:1:26: error: libxml/xpath.h: No such file or directory
    *********************************************************************************
    Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
    *********************************************************************************
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-cmQUrb/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-YFpKDF-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-cmQUrb/lxml

    No matching distribution found for python-pyquery

我知道它是因为我的 Python 版本 (2.6),由于 yum

我无法将它更新到 2.7

我该如何解决这个问题?

您缺少一些 OS 相关依赖项。

试试这个:

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

或者试试这个:

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

左右:

sudo apt install python-pyquery

您可能缺少 GCC 编译器向您吐出的 XML 依赖项,可以通过以下方式安装:

yum install libxslt-devel libxml2-devel libxml2 libxslt

安装每个开发和发布依赖项后,尝试:

pip install pyquery==1.2.4

哪个应该成功执行。您应该还可以使用以下方法更新 Python:here。 (可能取决于您的 OS 版本。)

以上方法说明:

yum install -y centos-release-SCL 
yum install -y python27

Okay for centos 6.4 also On apu.0xdata.loc, after this install was done

$ which python 
/usr/local/bin/python

$ python -V
Python 2.7.3

$ ls -ltr /usr/local/bin/pyth*
lrwxrwxrwx 1 root root      24 Jan 30  2013 /usr/local/bin/python -> /usr/local/bin/python2.7
-rwxr-xr-x 1 root root 6162289 Sep  3 00:59 /usr/local/bin/python2.7
-rwxr-xr-x 1 root root    1624 Sep  3 01:00 /usr/local/bin/python2.7-config

So yum will use '/usr/bin/python' which is 2.6

$ /usr/bin/python -V
Python 2.6.6

"python" will give you python 2.7.

"python2.7" will give you python 2.7.

"easy_install" and "easy_install-2.7" will easy install for python 2.7. While separate files, they both seem to install into /usr/local/lib/python2.7/site-packages/