python 安装easy_install...开始安装lxml
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2368008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing easy_install... to get to installing lxml
提问by Alex
I've come to grips with the fact that ElementTree isn't going to do what I want it to do. I've checked out the documentation for lxml, and it appears that it will serve my purposes. To get lxml, I need to get easy_install. So I downloaded it from here, and put it in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
. Then I went to that folder, and ran sh setuptools-0.6c11-py2.6.egg
.
我已经意识到 ElementTree 不会做我想让它做的事情。我已经检查了 lxml 的文档,它似乎可以满足我的目的。要获得lxml,我需要获得easy_install。所以我从这里下载它,并把它放在/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
. 然后我去了那个文件夹,然后运行sh setuptools-0.6c11-py2.6.egg
.
That installed successfully. Then I got excited because I thought the whole point of easy_install was that I could then just install via easy_install lxml, and lxml would magically get downloaded, built, and installed properly, ready for my importing enjoyment. So I ran easy_install lxml
. I pasted the results below. What should I do?
那安装成功了。然后我很兴奋,因为我认为 easy_install 的全部意义在于我可以通过 easy_install lxml 进行安装,并且 lxml 会神奇地被下载、构建和正确安装,为我的导入乐趣做好准备。所以我跑了easy_install lxml
。我把结果贴在下面。我该怎么办?
easy_install lxml
Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.2.6
Downloading http://codespeak.net/lxml/lxml-2.2.6.tgz
Processing lxml-2.2.6.tgz
Running lxml-2.2.6/setup.py -q bdist_egg --dist-dir /var/folders/49/49N0+g5QFKCm51AbzMtghE+++TI/-Tmp-/easy_install-rxbP6K/lxml-2.2.6/egg-dist-tmp-fjakR0
Building lxml version 2.2.6.
NOTE: Trying to build without Cython, pre-generated 'src/lxml/lxml.etree.c' needs to be available.
Using build configuration of libxslt 1.1.12
Building against libxml2/libxslt in the following directory: /usr/lib
unable to execute gcc-4.0: No such file or directory
error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1
回答by gotgenes
First off we don't use easy_install anymore. We use pip. Please use pip instead.
首先,我们不再使用easy_install。我们使用pip。请改用pip。
To get to your particular troubles, as the comments point out, you're missing GCC. On OS X, XcodeCommand Line Tools provides GCC, as well as many other programs necessary for building software on OS X. For OS X 10.9 (Mavericks) and newer, either install Xcode through the App Store, or alternatively, install only the Xcode Command Line Tools with
为了解决您的特定问题,正如评论指出的那样,您缺少 GCC。在 OS X 上,Xcode命令行工具提供 GCC,以及在 OS X 上构建软件所需的许多其他程序。对于 OS X 10.9(小牛)和更新版本,要么通过 App Store 安装 Xcode,要么只安装 Xcode命令行工具
xcode-select --install
For more details, please see the Apple Developer FAQor search the web for "install Xcode Command Line Tools".
有关更多详细信息,请参阅Apple Developer FAQ或在网络上搜索“安装 Xcode 命令行工具”。
For older versions of OS X, you can get Xcode Command Line Tools from the downloads page of the Apple Developer website(free registration required).
对于旧版本的 OS X,您可以从Apple Developer 网站的下载页面获取 Xcode Command Line Tools (需要免费注册)。
Once you have GCC installed, you may still encounter errors during compilation if the C/C++ library dependencies are not installed on your system. On OS X, the Homebrewproject is the easiest way to install and manage such dependencies. Follow the instructions on the Homebrew website to install Homebrew on your system, then issue
安装 GCC 后,如果系统上未安装 C/C++ 库依赖项,则在编译过程中可能仍会遇到错误。在 OS X 上,Homebrew项目是安装和管理此类依赖项的最简单方法。按照 Homebrew 网站上的说明在您的系统上安装 Homebrew,然后发出
brew update
brew install libxml2 libxslt
Possibly causing further trouble in your case, you placed the downloaded setuptools in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
. Please do not download any files to this location. Instead, I suggest you download the file to your home directory, or your usual Downloads
directory. After downloading it, you're supposed to run sh setuptools-X.Y.Z.egg
, which will then install it properly into the appropriate site-packages
and put the executable easy_install
on your path.
可能会在您的情况下造成进一步的麻烦,您将下载的 setuptools 放在/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
. 请不要将任何文件下载到此位置。相反,我建议您将文件下载到您的主目录或常用Downloads
目录。下载后,您应该运行sh setuptools-X.Y.Z.egg
,然后将其正确安装到适当的位置site-packages
并将可执行文件easy_install
放在您的路径上。
回答by Simplecoder
Ensure you have libxml2-dev and libxslt1-dev installed
确保已安装 libxml2-dev 和 libxslt1-dev
apt-get install libxml2-dev
apt-get install libxslt1-dev
Then your installation should build properly.
然后您的安装应该正确构建。
回答by TheLifeOfSteve
try:
sudo apt-get install python-lxml
尝试:
sudo apt-get install python-lxml
回答by Kevin P.
Make sure that all the following packages are installed on your system first:
确保首先在您的系统上安装了以下所有软件包:
gcc gcc-c++ python-devel libxml2 libxml2-dev libxslt libxslt-dev
You should be able to install them using some variant of: sudo apt-get install sudo yum install
您应该能够使用以下变体安装它们: sudo apt-get install sudo yum install
Only after all of the above have been successfully installed should you attempt to run:
只有在成功安装上述所有内容后,您才能尝试运行:
sudo pip install lxml
回答by John Feminella
It looks like lxml
wants to build an extension that requires access to a C compiler. You will need gcc
for that. Try running sudo apt-get install build-essential
and that should fix this particular issue.
看起来lxml
想要构建一个需要访问 C 编译器的扩展。您将需gcc
要这样做。尝试运行sudo apt-get install build-essential
,这应该可以解决这个特定问题。