Python Pythonpath模块安装 [英] Python Pythonpath Modules install
问题描述
我对在python中安装模块感到恼火,并且遇到了很多麻烦,因此找到一个好的解决方案将是很棒的.这是我的问题:
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:如何告诉easy_install/Python软件包安装位置?
即使我在.bash_profile
使用:
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.
- 我只是使用命令
easy_install south
安装"south",然后猜中了它,将其安装到了:
- I just install "south" with the command
easy_install south
and it installed it, guess, right into:
/Library/Python/2.6/site-packages
现在复制安装在此处的"south"(位于名为South-0.7.2-py2.6.egg
的文件夹中,我只是向南复制)并将其粘贴到
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
现在我可以在进入django项目的目录(在其中我具有"south"的settings.py-Installed Apps)和
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.
- 是否/必须为每个模块执行此操作?是否有更好的优雅方法来解决此问题.请说有.
谢谢
推荐答案
基于问题的路径(/Library/Frameworks/Python.framework/Versions/2.6
),您似乎还安装了除Apple提供的Python之外的其他Python.这是python.org OS X安装程序的标准安装路径.
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.
将easy_install
安装到正确的Python站点软件包位置的技巧是了解您拥有的每个 Python实例的 own 副本. easy_install
,并且您需要确保在安装软件包时使用的是正确的软件包.对于OS X 10.5和10.6,Apple在/usr/bin
中为其提供的Python提供easy_install
命令.例如,在10.6中:
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 of easy_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 supplies easy_install
commands in /usr/bin
for the Pythons it supplies. For example, in 10.6:
$ ls -l /usr/bin/easy_install*
-rwxr-xr-x 2 root wheel 925 Jun 30 2009 /usr/bin/easy_install*
-rwxr-xr-x 1 root wheel 421 Jun 30 2009 /usr/bin/easy_install-2.5*
-rwxr-xr-x 1 root wheel 421 Jun 30 2009 /usr/bin/easy_install-2.6*
它们将安装到/Library/Python/2.x/
中的适当位置,这是Apple提供的Python默认查找站点包的位置.
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.
对于python.org Python,默认站点包位置在/Library/Frameworks/Python.framework/Versions/x.y
中.在适当的目录下,有一个您找到的lib/pythonx.y/site-packages
和一个bin
目录.要使Python成为默认位置,请确保bin
目录位于您的Shell PATH上且位于/usr/bin/
之前,所以类似:
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 a lib/pythonx.y/site-packages
as you found and also a bin
directory. To make the Python there the default, make sure that that bin
directory is on your shell PATH and comes before /usr/bin/
, so something like:
export PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"
默认情况下,python.org安装程序会尝试修改您的shell配置文件(如.bash_profile
)来执行此操作.然后按照说明安装提供传统版本easy_install
的 setuptools ,或分发,这是easy_install
的最新版本.然后,您应该在框架bin
目录中看到一个easy_install
命令:
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 of easy_install
, or Distribute, the more cutting-edge version of easy_install
. You should then see aneasy_install
command in the framework bin
directory:
$ cd /Library/Frameworks/Python.framework/Versions/2.6
$ ls -l bin/easy_install*
-rwxr-xr-x 1 nad admin 360 Aug 25 07:30 bin/easy_install*
-rwxr-xr-x 1 nad admin 368 Aug 25 07:30 bin/easy_install-2.6*
,并且,如果您使用它来安装软件包,它们将最终安装在正确的位置,一切都会很愉快.
and, if you use it to install packages, they will end up in the right place and everything will be happy.
这篇关于Python Pythonpath模块安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!