【问题标题】:How do I get easy_install to install modules to the correct directory?如何让 easy_install 将模块安装到正确的目录?
【发布时间】:2012-03-11 21:24:19
【问题描述】:

我正在尝试使用 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还在用错目录?!高度赞赏帮助。谢谢。

【问题讨论】:

    标签: python easy-install


    【解决方案1】:

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

    【讨论】:

    • 我尝试通过import sys sys.path.append('...') 添加 /Users/myuser/Library/Python/2.7/site-packages/ 但是当我重新启动 shell 并打印 sys.path 时,我刚刚添加的目录不是列出。这一切看起来都很奇怪。
    • 是的,如果你执行 sys.path.append() 它只会在你的 shell 会话期间停留在那里。您需要将其添加到主目录中的 .bashrc 文件中。执行 cd / -> nano (或 vim 或任何你认为最简单的) .bashrc -> 将其粘贴到那里:export PYTHONPATH=$PYTHONPATH:$/Library/Python/2.7/site-packages/ -> save
    • 我将此添加到我的 .profile 中,但仍然面临同样的问题。有没有办法查看 easy_install 在哪里写入更改?
    • 当我运行sudo easy_install mechanize -d /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages 时输出为:Searching for -d Reading http://pypi.python.org/simple/-d/ Couldn't find index page for '-d' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading http://pypi.python.org/simple/ No local packages or download links found for -d error: Could not find suitable distribution for Requirement.parse('-d')
    • -d 应该在 mechanize 前面,如sudo easy_install -d /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages mechanize
    【解决方案2】:

    一种方法是为您尝试使用的python 安装安装setuptools(具有easy_install)。所以,使用你的符号链接的python,关注these instructions,然后,在/Library/Frameworks/Python.framework/Versions/2.7/Scripts中使用easy_install而不是~/Library/Python/2.7/Scripts

    【讨论】:

    • 我运行 setuptools-installation 并将 -d 设置为 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages 但我仍然无法访问已安装的模块。它没有给我任何错误消息,但我不确定安装是否发生了任何变化。
    • 您可以尝试sudo /Library/Frameworks/Python.framework/Versions/2.7/Scripts/easy_install mechanize,而不是路径中的典型easy_install 吗?我不能 100% 确定这是正确的目录,因为我从未在 Mac 上使用过 python。否则我不知道还能尝试什么。
    • 这会产生以下输出:Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/easy_install-2.7", line 8, in <module> load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install-2.7')() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 318, in load_entry_point ImportError: Entry point ('console_scripts', 'easy_install-2.7') not found
    • 是的,setuptools 很奇怪。那时这个解决方案可能行不通。
    【解决方案3】:

    您应该可以使用 --install-dir=DIR 指定安装目录

    查看http://packages.python.org/distribute/easy_install.html#command-line-options 了解更多精美选项!不过需要注意的一点是,您指定的目录必须在您的 python 路径中。

    【讨论】:

      【解决方案4】:

      原来我的 PATH 有问题。将 /usr/local/share/python 移动到我的 PATH 顶部并通过自制软件重新安装 python 解决了我的问题。

      如果问题仍然存在,请务必尝试运行 brew doctor 并按照那里的建议进行操作!

      【讨论】:

        猜你喜欢
        • 2013-04-25
        • 1970-01-01
        • 1970-01-01
        • 2010-10-07
        • 1970-01-01
        • 2020-10-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多