Python Pythonpath 模块安装
我对在 python 中安装模块感到有点恼火,并且遇到了很多麻烦,所以如果能找到一个好的解决方案那就太棒了。以下是我的问题:
- PYTHONPATH:如何告诉 easy_install/Python 在哪里安装我的包?
即使我将: /Library/Python/2.6/site-packages
放在我的 .bash_profile
中
:
PYTHONPATH="/Library/Python/2.6/site-packages"
export PYTHONPATH
它不会导入我在那里的包。
在另一个网站上,我放入的所有内容:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
有效。我不知道为什么,也很想知道。
- 我只是使用命令
easy_install South
安装“south”,猜猜,它安装到了:
/Library/Python/2.6/site-packages
现在复制了“south”它安装在那里(它位于一个名为:South-0.7.2-py2.6.egg
的文件夹中,我刚刚复制了south)并将其粘贴到
/Library/Frameworks/Python。 Framework/Versions/2.6/lib/python2.6/site-packages
现在我可以在转到我的 django 项目目录时导入它(其中 settings.py-Installed Apps 我有“south”)和
< 根据 South的
说法,这是一个很好的指标,表明它可以工作。
- 我可以/必须为每个模块都这样做吗?有没有更好优雅的方法来解决这个问题。请说有。
谢谢
I am kind of annoyed by the installation of modules in python and had a lot of trouble with it, so it would be fantastic to find a good solution for it. Here are my issues:
- PYTHONPATH: How can I tell easy_install/Python where to install my packages?
Even though I put: /Library/Python/2.6/site-packages
in my .bash_profile
With:
PYTHONPATH="/Library/Python/2.6/site-packages"
export PYTHONPATH
It wont import packages I have there.
On the other site everything I put into:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
Works. I dont know why and would love to know.
- I just install "south" with the command
easy_install south
and it installed it, guess, right into:
/Library/Python/2.6/site-packages
Now copied "south" Which was installed there (it was in a Folder called: South-0.7.2-py2.6.egg
, i just copied south) and pasted it to
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
And now I can import it when going to directory of my django project (in which settings.py-Installed Apps I have 'south') and
python manage.py shell
Which according to south is a good indicator that it works.
- Can/Do I have to do that for every module? Is there a better elegant way to solve this. Please say there is.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据您问题中的路径 (
/Library/Frameworks/Python.framework/Versions/2.6
),除了 Apple 提供的 Python 之外,您似乎还安装了额外的 Python。这是 python.org OS X 安装程序的标准安装路径。让
easy_install
安装到正确的 Python 站点包位置的技巧是了解您拥有的每个 Python 实例都需要有其自己的easy_install
的副本,并且您需要确保在安装软件包时使用正确的副本。对于 OS X 10.5 和 10.6,Apple 在/usr/bin
中为其提供的 Python 提供了easy_install
命令。例如,在 10.6 中:它们将安装到
/Library/Python/2.x/
中的适当位置,这是 Apple 提供的 Python 默认查找站点包的位置。对于 python.org Python,默认站点包位置位于
/Library/Frameworks/Python.framework/Versions/xy
中。在相应的目录下有一个lib/pythonx.y/site-packages
正如您所发现的,还有一个bin
目录。要使 Python 成为默认目录,请确保bin
目录位于您的 shell PATH 上,并且位于/usr/bin/
之前,例如:python.org默认情况下,安装程序会尝试修改您的 shell 配置文件(例如
.bash_profile
)来执行此操作。然后按照说明安装 setuptools,它提供传统版本的easy_install< /code> 或 分发,
easy_install.然后,您应该在框架
bin
目录中看到一个easy_install
命令:并且,如果您使用它来安装软件包,它们最终会出现在正确的位置,一切都会很顺利。
Based on the path (
/Library/Frameworks/Python.framework/Versions/2.6
) in your question, you appear to have installed an additional Python besides the ones supplied by Apple. That's the standard installation path for the python.org OS X installer.The trick to getting
easy_install
to install to the right Python site-packages location is to understand that each Python instance you have needs to have its own copy ofeasy_install
and you need to make sure you are using the right one when you install a package. For OS X 10.5 and 10.6, Apple supplieseasy_install
commands in/usr/bin
for the Pythons it supplies. For example, in 10.6:They will install into the appropriate locations in
/Library/Python/2.x/
which is where the Apple-supplied Pythons look for site-packages by default.For a python.org Python, the default site-package locations are in
/Library/Frameworks/Python.framework/Versions/x.y
. Under the appropriate directory there is alib/pythonx.y/site-packages
as you found and also abin
directory. To make the Python there the default, make sure that thatbin
directory is on your shell PATH and comes before/usr/bin/
, so something like:The python.org installers by default try to modify your shell profile files, like
.bash_profile
, to do this. Then follow the instructions to install either setuptools, which supplies the traditional version ofeasy_install
, or Distribute, the more cutting-edge version ofeasy_install
. You should then see aneasy_install
command in the frameworkbin
directory:and, if you use it to install packages, they will end up in the right place and everything will be happy.
easy_install
的-d
参数告诉它在哪里安装模块。The
-d
argument toeasy_install
tells it where to install the module(s).sudo env ARCHFLAGS="-arch x86_64" easy_install-2.7 lxml
适用于 Mac OS 10.9。确保在easy_install
命令中限定您使用的 python 版本。sudo env ARCHFLAGS="-arch x86_64" easy_install-2.7 lxml
worked on Mac OS 10.9. Make sure to qualify the version of python you are using in theeasy_install
command.