방금 MacPorts와 함께 설치한 일부 Python 라이브러리(PIL, psycopg2)를 가져올 수 없습니다. 이 포럼을 살펴보고 이 문제를 해결하기 PATH
위해 변수를 조정하려고 시도했지만 ~/.bash_profile
작동하지 않았습니다.
PIL과 psycopg2의 위치를 PATH
. 터미널이 MacPorts에서 설치한 버전이 아닌
에서 Python 버전을 사용하고 있다는 것을 알고 있습니다 ./usr/local/bin
/opt/local/bin
터미널에서 Python을 사용할 때 PIL 및 psycopg2가 sys.path에 있는지 확인하려면 MacPorts 버전의 Python을 사용해야 합니까? 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
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
위의 내용 중 하나라도 어리석거나 잘못된 생각으로 보인다면 어떤 비판이나 의견도 환영합니다. 나는 이 모든 것을 처음 접했습니다. 감사해요!
MacBook Pro에서 OSX 10.6.5를 실행하고 터미널에서 Python 2.6.1을 호출합니다.
답변1
Python을 설치한 후 'notes' 명령을 사용하십시오(python26을 설치한 버전으로 변경).
$ port notes python26
설치 후 권장 사항에는 몇 가지 변형이 표시됩니다.
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
기본 Python을 설치 python_select
한 다음 선택 해야 합니다 . python26
그런 다음 실제로 MacPorts(예: port install py26-psycopg2 py26-pil
)를 사용하여 PIL 및 pyscopg2를 설치했다면 지정할 필요가 없습니다.아무것안에 PYTHONPATH
. 또한 /opt/local/Library/Frameworks/…
. PATH
이 작업을 수행한 후에 which python
는 를 반환해야 합니다 /opt/local/bin/python
. MacPorts에 의해 설치된 Python 포트는 이미 MacPorts Python /opt/local/Library/Frameworks/Python.framework
에 있습니다 . MacPorts Python 패키지에 대한 지식이 없는 sys.path
System Python(예: )을 사용했기 때문에 이전에는 해당 항목을 찾지 못했습니다 ./usr/bin/python
답변2
나생각하다나는 내 질문에 대한 답을 알아냈다. 포함하도록 ~/.bash_profile 파일을 편집했습니다.
export PYTHONPATH=
그런 다음 기존 경로를 모두 추가했습니다 sys.path
.
export PYTHONPATH=/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:/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:
그런 다음 MacPorts가 항목을 설치한 디렉토리에 경로를 추가했습니다.
/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:
이제 sys.path를 인쇄하면 MacPorts 설치 디렉터리의 경로가 포함됩니다.
/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
/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
/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
지금
>>> import PIL
그리고
>>> import psycopg2
잘 작동합니다.