如何轻松安装以将模块安装到正确的目录?

2024-05-16 09:22:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用easy_install安装一个新模块。

当我运行类似于

sudo easy_install foo

foo安装到~/Library/Python/2.7/site-packages/

这似乎是错误的,因为我不能使用python shell中安装的任何模块。

根据我在阅读了一些与easy_install问题相关的SO文章后的理解,正确的目录应该是/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages ,因为我的python shell使用了/usr/local/bin/python,它象征性地链接到所述目录。

如何告诉easy_install使用此目录而不是当前目录?

谢谢你

朱利安

编辑:我使用-d /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages选项重新运行setuptools安装。结果如下:

Processing setuptools-0.6c11-py2.7.egg
Removing /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
setuptools 0.6c11 is already the active version in easy-install.pth
Installing easy_install script to /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Installing easy_install-2.7 script to /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

Installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11

例如sudo easy_install mechanize的输出是

Searching for mechanize
Best match: mechanize 0.2.5
Processing mechanize-0.2.5-py2.7.egg
mechanize 0.2.5 is already the active version in easy-install.pth

Using /Users/julian/Library/Python/2.7/site-packages/mechanize-0.2.5-py2.7.egg
Processing dependencies for mechanize
Finished processing dependencies for mechanize

似乎easy_install仍然使用错误的目录?!非常感谢你的帮助。谢谢您。


Tags: install目录foregglibpackageseasylibrary
3条回答

您应该能够使用--install dir=dir指定安装目录

请查看http://packages.python.org/distribute/easy_install.html#command-line-options以获取更多有趣的选项!但有一点需要注意,您指定的目录必须在python路径上。

一种方法是为您尝试使用的python安装安装setuptools(安装简单)。因此,使用符号链接的python,遵循these instructions,然后使用/Library/Frameworks/Python.framework/Versions/2.7/Scripts中的easy_install,而不是~/Library/Python/2.7/Scripts

可以使用--prefix设置要安装包的路径。或者将/Library/Python/2.7/site-packages/添加到Python路径。

相关问题 更多 >