正在安装 easy_install...开始安装 lxml
我已经意识到 ElementTree 不会做我想要它做的事情。我已经查看了 lxml 的文档,看来它可以满足我的目的。要获取 lxml,我需要获取 easy_install。所以我从这里下载了它,并把它位于 /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ 中。然后我转到该文件夹,并运行 sh setuptools-0.6c11-py2.6.egg
。
这样就安装成功了。然后我很兴奋,因为我认为 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
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
.
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
首先,我们不再使用 easy_install 。我们使用 pip。请使用 pip 代替。
正如评论指出的那样,为了解决您的特殊麻烦,您错过了 GCC。在 OS X 上,Xcode 命令行工具提供了 GCC 以及许多其他必要的程序在 OS X 上构建软件。对于 OS X 10.9 (Mavericks) 及更高版本,可以通过 App Store 安装 Xcode,或者仅安装 Xcode 命令行工具。
有关更多详细信息,请参阅 Apple 开发者常见问题解答 或搜索web“安装 Xcode 命令行工具”。
对于旧版本的 OS X,您可以从 Apple Developer 的 下载页面获取 Xcode 命令行工具网站(需要免费注册)。
安装 GCC 后,如果系统上未安装 C/C++ 库依赖项,则在编译过程中仍可能会遇到错误。在 OS X 上,Homebrew 项目是安装和管理此类依赖项的最简单方法。按照 Homebrew 网站上的说明在您的系统上安装 Homebrew,然后发出问题
可能会导致您的情况进一步出现问题,您将下载的 setuptools 放在
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2 中。 6/站点包/
。请不要将任何文件下载到此位置。相反,我建议您将该文件下载到您的主目录或常用的Downloads
目录中。下载后,您应该运行sh setuptools-XYZegg
,然后将其正确安装到相应的site-packages
中,并放入可执行文件easy_install< /code> 在你的路径上。
First off we don't use easy_install anymore. We use pip. Please use pip instead.
To get to your particular troubles, as the comments point out, you're missing GCC. On OS X, Xcode Command 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
For more details, please see the Apple Developer FAQ or search the web for "install Xcode Command Line Tools".
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).
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 Homebrew project 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
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 usualDownloads
directory. After downloading it, you're supposed to runsh setuptools-X.Y.Z.egg
, which will then install it properly into the appropriatesite-packages
and put the executableeasy_install
on your path.确保安装了 libxml2-dev 和 libxslt1-dev
然后您的安装应该正确构建。
Ensure you have libxml2-dev and libxslt1-dev installed
Then your installation should build properly.
尝试:
sudo apt-get install python-lxml
try:
sudo apt-get install python-lxml
看起来
lxml
想要构建一个需要访问 C 编译器的扩展。为此,您将需要 gcc。尝试运行 sudo apt-get install build-essential ,这应该可以解决这个特定问题。It looks like
lxml
wants to build an extension that requires access to a C compiler. You will needgcc
for that. Try runningsudo apt-get install build-essential
and that should fix this particular issue.确保首先在您的系统上安装以下所有软件包:
您应该能够使用以下版本来安装它们:
须藤 apt-get 安装
sudo yum install
只有在成功安装上述所有内容后,您才可以尝试运行:
Make sure that all the following packages are installed on your system first:
You should be able to install them using some variant of:
sudo apt-get install
sudo yum install
Only after all of the above have been successfully installed should you attempt to run: