这是我的错误:
(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install lxml
Downloading/unpacking lxml
Running setup.py egg_info for package lxml
Building lxml version 2.3.
Building without Cython.
ERROR: /bin/sh: xslt-config: not found
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
Installing collected packages: lxml
Running setup.py install for lxml
Building lxml version 2.3.
Building without Cython.
ERROR: /bin/sh: 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/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:4: fatal error: Python.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-jOhgvD-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6:
Building lxml version 2.3.
Building without Cython.
ERROR: /bin/sh: 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
running build_ext
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:4: fatal error: Python.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-jOhgvD-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log
我该怎么办?
更新
(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install lxml
Downloading/unpacking lxml
Running setup.py egg_info for package lxml
Building lxml version 2.3.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib
Installing collected packages: lxml
Running setup.py install for lxml
Building lxml version 2.3.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:4: fatal error: Python.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-NJw2ws-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6:
Building lxml version 2.3.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib
running install
running build
running build_py
running build_ext
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:4: fatal error: Python.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-NJw2ws-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log
日志:
------------------------------------------------------------
/home/zjm1126/zjm_test/mysite/bin/pip run on Thu Mar 3 17:07:27 2011
Downloading/unpacking mysql-python
Running setup.py egg_info for package mysql-python
running egg_info
creating pip-egg-info/MySQL_python.egg-info
writing pip-egg-info/MySQL_python.egg-info/PKG-INFO
writing top-level names to pip-egg-info/MySQL_python.egg-info/top_level.txt
writing dependency_links to pip-egg-info/MySQL_python.egg-info/dependency_links.txt
writing pip-egg-info/MySQL_python.egg-info/PKG-INFO
writing top-level names to pip-egg-info/MySQL_python.egg-info/top_level.txt
writing dependency_links to pip-egg-info/MySQL_python.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/MySQL_python.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
reading manifest file 'pip-egg-info/MySQL_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'MANIFEST'
warning: no files found matching 'ChangeLog'
warning: no files found matching 'GPL'
writing manifest file 'pip-egg-info/MySQL_python.egg-info/SOURCES.txt'
Installing collected packages: mysql-python
Running setup.py install for mysql-python
Running command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6
running install
running build
running build_py
creating build
creating build/lib.linux-i686-2.6
copying _mysql_exceptions.py -> build/lib.linux-i686-2.6
creating build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-i686-2.6/MySQLdb
creating build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-i686-2.6
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-i686-2.6/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
In file included from _mysql.c:29:
pymemcompat.h:10: fatal error: Python.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6:
running install
running build
running build_py
creating build
creating build/lib.linux-i686-2.6
copying _mysql_exceptions.py -> build/lib.linux-i686-2.6
creating build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-i686-2.6/MySQLdb
creating build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-i686-2.6
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-i686-2.6/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
In file included from _mysql.c:29:
pymemcompat.h:10: fatal error: Python.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
Exception information:
Traceback (most recent call last):
File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/basecommand.py", line 130, in main
self.run(options, args)
File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/commands/install.py", line 228, in run
requirement_set.install(install_options, global_options)
File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/req.py", line 1043, in install
requirement.install(install_options, global_options)
File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/req.py", line 559, in install
cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/__init__.py", line 249, in call_subprocess
% (command_desc, proc.returncode))
InstallationError: Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
答案 0 :(得分:458)
**确保安装了libxml2和libxslt的开发包**
从lxml documentation开始,假设您正在运行基于Debian的发行版:
sudo apt-get install libxml2-dev libxslt-dev python-dev
对于基于Debian的系统,应该足以安装python-lxml
或python3-lxml
的已知构建依赖关系,例如
sudo apt-get build-dep python3-lxml
答案 1 :(得分:104)
这对我有用:
yum install libxslt-devel libxml2-devel
答案 2 :(得分:75)
如果您使用的是Ubuntu / Lubuntu 13.04或Ubuntu 13.10并且遇到“/ usr / bin / ld:找不到-lz”的问题,您可能还需要安装zlib1g-dev软件包:
sudo apt-get install -y zlib1g-dev
把它们放在一起:
sudo apt-get install -y libxml2-dev libxslt1-dev zlib1g-dev python3-pip
sudo pip3 install lxml
答案 3 :(得分:33)
不,你错过了Python头文件。当您使用系统Python时,这主要发生在Linux上(有reasons not to do that,但这是一个不同的问题)。
你可能需要安装一些软件包,它可能叫做python-dev或python-devel。
sudo yum install python-devel
或
sudo aptitude install python-dev
或者某些人。
答案 4 :(得分:9)
我通过增加服务器内存解决了这个问题。
我只运行512 MB,当我升级到1 GB时,我没有问题。
我还在此之前手动安装了每个软件包以尝试解决问题,但我不确定这是否是必要步骤。
答案 5 :(得分:8)
在Windows上我在3.3上安装Python 3.4后尝试手动安装时,我在Windows上遇到了同样的错误。我终于能够通过从Python34目录安装滚轮和运行pip来解决它。
1)从这里下载轮:http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
2)cd Python34\Scripts
3)pip.exe C:\Users\Home\Downloads\lxml- ......... .whl
答案 6 :(得分:7)
只需安装要求:
sudo apt-get install libxml2-dev libxslt-dev python-dev
现在,您可以使用pip包管理工具安装它:
pip install lxml
答案 7 :(得分:6)
我正在使用Ubuntu 14.04,这解决了我的问题
sudo apt-get build-dep python3-lxml
sudo apt-get install libxml2-dev libxslt-dev python-dev
答案 8 :(得分:6)
error: command 'gcc' failed with exit status 1
yum remove audit
yum install gcc
yum install libxslt-devel libxml2-devel
cd lxml-x.x.x
python setup.py build
python setup.py install
答案 9 :(得分:5)
STATIC_DEPS=true easy_install lxml
答案 10 :(得分:4)
安装lxml二进制文件就可以了。 Check this
答案 11 :(得分:3)
我在使用lxml的pip安装时遇到了这个问题。我的CentOS实例使用的是python 2.6,它抛出了这个错误。
为了解决这个问题,我使用Python 2.7进行了以下操作:
sudo yum install python-devel
sudo yum install libxslt-devel libxml2-devel
/usr/bin/python2.7 YOUR_PYTHON_COMMAND
运行命令
(对我而言,这是/usr/bin/python2.7 -m pip install lxml
)答案 12 :(得分:3)
sudo apt install libxslt-dev libxml2-dev
然后尝试升级python setuptools
pip install -U pip setuptools
这应该解决它。
答案 13 :(得分:2)
上述所有答案都假定用户可以访问特权/ root帐户来安装所需的库。要在本地安装它,您需要执行以下步骤。仅显示概述,因为根据您可能缺少的依赖性,步骤可以稍微涉及
1.下载并编译libxml2-2.9.1& libxslt-1.1.28(版本可能会改变)
2.使用configure将libxml和libxslt的每个安装路径配置为某个本地目录。防爆。 ./configure --prefix=/home_dir/dependencies/libxslt_path
3.Run make
然后make install
4.从源
下载并编译lxml答案 14 :(得分:2)
pymemcompat.h:10: fatal error: Python.h: 没有那个文件或目录
男孩,您应该使用LANG=C
发布错误日志,否则人们无法从您的日志中找到真正的原因。上面的日志说:没有这样的文件或目录。
这意味着您应该安装Python的开发包。这通常是Debian风味发行版上的“python-dev”,以及RHEL风格发行版上的“python-devel”。
答案 15 :(得分:2)
我知道我迟到了,
但如果没有别的办法,这将有所帮助
mkdir ~/tmp
export TMPDIR=~/tmp
STATIC_DEPS=true easy_install-2.7 lxml
设置TMPDIR将确保构建可以运行它需要运行的所有内容,并且设置STATIC_DEPS将告诉它引入自己的libxml2和 libxslt2,而不是使用服务器上安装的旧版本。
答案 16 :(得分:2)
这适用于我,12.04,python2.7.6
sudo apt-get install libxml2 libxml2-dev libxslt1-dev
sudo pip install lxml
答案 17 :(得分:1)
唯一对我有帮助的是
sudo apt-get install python3.5-dev
答案 18 :(得分:1)
我的Linux机器上出现了同样的错误。如果你去了他们文档中的website那么。如果你在 Linux机器中遇到这种错误,请试试这些命令,
# apt install libxml2-dev libxslt-dev python-dev
# pip install lxml==3.4.4
答案 19 :(得分:1)
在Windows 8中使用cygwin 64.
我有......
pip install lxml (...)
gcc -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python3/python3-3.2.5-4.x86_64/build=/usr/src/debug/python3-3.2.5-4 -fdebug-prefix-map=/usr/src/ports/python3/python3-3.2.5-4.x86_64/src/Python-3.2.5=/usr/src/debug/python3-3.2.5-4 -I/usr/include/libxml2 -I/tmp/pip-build-b8ybku/lxml/src/lxml/includes -I/usr/include/python3.2m -c src/lxml/lxml.etree.c -o build/temp.cygwin-1.7.34-x86_64-3.2/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:8:22: fatal error: pyconfig.h: No such file or directory
compilation terminated.
/usr/lib/python3.2/distutils/dist.py:257: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python3.2m -c "import setuptools, tokenize;__file__='/tmp/pip-build-b8ybku/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-u3vwj8-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-b8ybku/lxml
我已经尝试了一切,直到我意识到新的cygwin工具链搞砸了python逻辑。 cygwin安装一个名为" realgcc"的编译器。这不是真正的 gcc。
解决方案
安装gcc。例如:
apt-cyg install gcc-g++
答案 20 :(得分:0)
将Windows 7与Cygwin一起使用,我遇到了:
Compile failed: command 'gcc' failed with exit status 1
cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitZsgdMQ.c -o tmp/xmlXPathInitZsgdMQ.o
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'gcc' failed with exit status 1
我通过安装mingw64-x86_64-libxslt
答案 21 :(得分:0)
我在Windows机器上工作。这里有一些成功安装lxml的指针(使用python 2.6及更高版本)。
安装以下内容:
pip install
无法使用所有内容。
找到了libxslt here。
完成上述两项后,
执行:pip install lxml
。
另一种解决方法是使用PyPI的稳定版本或Christoph Gohlke的非官方Windows二进制文件(found here)。
答案 22 :(得分:0)
在osx 10.10.5和virtualenv中,也许你可以像下面这样解决这个问题:
sudo C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/libxml:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include pip install -r lxml
答案 23 :(得分:0)
以下文件在Windows上为我工作 https://pypi.python.org/pypi/lxml/3.3.3#downloads
答案 24 :(得分:0)
如果您已经安装了libxml2和libxslt,可能需要在libxml2和libxslt路径之间创建一个符号链接到python2.6 include path。您也可以尝试添加INCLUDE环境参数。 因为gcc命令只搜索此路径:-I / usr / include / python2.6。
答案 25 :(得分:0)
我正在使用Ubuntu 12,这对我有用:
sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
sudo apt-get install python-dev
sudo apt-get install lxml
答案 26 :(得分:0)
这两个软件包需要分别安装,通常不能使用pip
安装。因此,对于FreeBSD:
Download a compressed snapshot of the Ports Collection into /var/db/portsnap:
# portsnap fetch
When running Portsnap for the first time, extract the snapshot into /usr/ports:
# portsnap extract
After the first use of Portsnap has been completed as shown above, /usr/ports can be updated as needed by running:
# portsnap fetch
# portsnap update
Now Install:
cd /usr/ports/textproc/libxml2
make install clean
cd /usr/ports/textproc/libxslt
make install clean
你应该很好...
答案 27 :(得分:-1)
对于Windows:
pip install --upgrade pip wheel
pip install bzt
pip install lxml