Ben*_*der 1 terminal python path macports osx-snow-leopard
我无法导入我刚安装在 MacPorts 上的一些 python 库(PIL、psycopg2)。我浏览了这些论坛,并尝试调整我的PATH变量~/.bash_profile以解决此问题,但没有奏效。
我将 PIL 和 psycopg2 的位置添加到PATH.
我知道终端使用的是 python 版本,/usr/local/bin而不是 MacPorts 在/opt/local/bin.
当我在终端中使用 python 时,是否需要使用 MacPorts 版本的 Python 以确保 PIL 和 psycopg2 位于 sys.path 上?我应该切换到 MacPorts 版本的 Python,还是会导致更多问题?
如果有帮助,这里有更多事实:
PIl 和 psycopg2 安装在 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
which python返回/usr/bin/python
$ echo $PATH返回(我将每条路径分开以便于阅读):
:/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
:/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
:/opt/local/bin
:/opt/local/sbin
:/usr/local/git/bin
:/usr/bin
:/bin
:/usr/sbin
:/sbin
:/usr/local/bin
:/usr/local/git/bin
:/usr/X11/bin
:/opt/local/bin
Run Code Online (Sandbox Code Playgroud)
在 python 中,>>> sys.path返回:
/Library/Frameworks/SQLite3.framework/Versions/3/Python
/Library/Python/2.6/site-packages/numpy-override
/Library/Frameworks/GDAL.framework/Versions/1.7/Python/site-packages
/Library/Frameworks/cairo.framework/Versions/1/Python
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload
/Library/Python/2.6/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode
Run Code Online (Sandbox Code Playgroud)
我欢迎任何批评和评论,如果上述任何内容看起来很愚蠢或构思不佳。我对这一切都很陌生。谢谢!
在 MacBook Pro 上运行 OSX 10.6.5,从终端调用 python 2.6.1
安装python后使用'notes'命令(将python26更改为您安装的任何版本):
$ port notes python26
Run Code Online (Sandbox Code Playgroud)
您会看到安装后建议的一些变化:
python26 has the following notes:
To fully complete your installation and make python 2.6 the default, please
run:
sudo port install python_select
sudo port select python python26
Run Code Online (Sandbox Code Playgroud)
您应该安装python_select并选择python26作为默认 Python。然后,如果你确实安装PIL和使用的MacPorts(即类似pyscopg2 port install py26-psycopg2 py26-pil),那么你应该不必指定任何东西在PYTHONPATH。您也不需要将/opt/local/Library/Frameworks/…目录添加到您的PATH. 这样做后,which python应该返回/opt/local/bin/python。MacPorts 中安装的 Python 端口/opt/local/Library/Frameworks/Python.framework已经在sys.pathMacPorts Python 中。您没有更早地找到它们,因为您使用的是 System Python(即/usr/bin/python),它不了解 MacPorts Python 包。
| 归档时间: |
|
| 查看次数: |
15298 次 |
| 最近记录: |