我在MacOs Sierra。
我遇到一个问题,即使用sudo pip install -e
安装我自己的软件包导致/usr/local/lib/python2.7/site-packages/easy-install.pth
更新为指向软件包,但在python启动时显然找不到。
这有点像我将/usr/local/bin/python
与/usr/bin/python
链接到一段时间以解决我不能再回忆的其他版本冲突类型问题。
是否有一种明智的方法可以通过编辑内容来解决这个问题,例如site.py
?
我不确定这里可能需要哪些其他细节。这是系统的大量相关命令输出。
pip安装似乎成功了:
~$ cd workspace/mypackage
mypackage$ sudo -H pip install -e .
Obtaining file:///Users/me/workspace/mypackage
...[snip]...
Running setup.py develop for mypackage
Successfully installed boto3-1.4.4 botocore-1.5.46 mypackage docutils-0.13.1 functools32-3.2.3.post2 futures-3.1.1 jmespath-0.9.2 jsonschema-2.6.0 python-dateutil-2.6.0 s3transfer-0.1.10
mypackage$ cd /tmp
tmp$ python -c 'import mypackage'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named mypackage
这里是python版本的外观。同样,指向/usr/bin/python
(并将原始/usr/local/bin/python
移至-cellar
)的链接是我之前遇到的另一个问题(特定于MacOs python,IIRC?)的解决方法。
tmp$ which python
/usr/local/bin/python
tmp$ ls -l $(which python)
lrwxr-xr-x 1 me admin 15 Apr 24 11:59 /usr/local/bin/python -> /usr/bin/python
tmp$ ls /usr/local/bin/python2.7*
python2.7 python2.7-cellar python2.7-config python2.7-config-cellar
tmp$ /usr/local/bin/python2.7-cellar --version
Python 2.7.13
tmp$ /usr/bin/python --version
Python 2.7.10
-cellar
版本的python确实找到了安装:
$ /usr/local/bin/python2.7-cellar -c 'import mypackage; print mypackage.__file__'
/usr/local/lib/python2.7/site-packages/mypackage/__init__.pyc
安装更新的easy-install.pth
位于/usr/local/lib
。
tmp$ sudo find /usr -name easy-install.pth
/usr/local/lib/python2.7/site-packages/easy-install.pth
tmp$ cat /usr/local/lib/python2.7/site-packages/easy-install.pth
/Users/me/workspace/mypackage
一些pip
详细信息:
tmp$ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)
tmp$ which pip
/usr/local/bin/pip
ls -l /usr/local/bin/pip
lrwxr-xr-x 1 me admin 31 Apr 22 21:27 /usr/local/bin/pip -> ../Cellar/python/2.7.13/bin/pip
tmp$ sudo find /usr -name pip
/usr/local/bin/pip
/usr/local/Cellar/ansible/2.3.0.0/libexec/bin/pip
/usr/local/Cellar/ansible/2.3.0.0/libexec/lib/python2.7/site-packages/pip
/usr/local/Cellar/python/2.7.13/bin/pip
/usr/local/Cellar/python/2.7.13/libexec/pip
/usr/local/Cellar/python/2.7.13/libexec/pip/build/lib/pip
/usr/local/Cellar/python/2.7.13/libexec/pip/pip
/usr/local/lib/python2.7/site-packages/pip
tmp$ ls -ld /usr/local/lib/python2.7/site-packages/pip
drwxr-xr-x 34 me admin 1156 Apr 22 21:27 /usr/local/lib/python2.7/site-packages/pip
在/usr/lib/python2.7下没有相应的pip或easy-install.pth的网站包:
$ ls -ld /usr/lib/python2.7
lrwxr-xr-x 1 root wheel 75 Oct 21 2016 /usr/lib/python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
tmp$ ls /usr/lib/python2.7/site*
/usr/lib/python2.7/site.py /usr/lib/python2.7/site.pyc /usr/lib/python2.7/site.pyo
我的sys.path
:
tmp$ python -c 'import sys; print "\n".join(sys.path)'
/usr/local/Cellar/apache-spark/2.1.0/libexec/python
/usr/local/lib/python2.7
/usr/local/lib/python2.7/site-packages
/usr/lib/python27.zip
/usr/lib/python2.7
/usr/lib/python2.7/plat-darwin
/usr/lib/python2.7/plat-mac
/usr/lib/python2.7/plat-mac/lib-scriptpackages
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/Library/Python/2.7/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Alles Normal in virtualenv:
mypackage$ mkvirtualenv testpip
...[snip]...
(testpip) mypackage$ sudo -H pip install -e .
Obtaining file:///Users/me/workspace/mypackage
Installing collected packages: mypackage
Running setup.py develop for mypackage
Successfully installed mypackage
(testpip) mypackage$ ls ~/.virtualenvs/testpip/lib/python2.7/site-packages/mypackage.egg-link
/Users/me/.virtualenvs/testpip/lib/python2.7/site-packages/mypackage.egg-link
(testpip) mypackage$ cd /tmp
(testpip) tmp$ python -c 'import mypackage; print mypackage.__file__'
/Users/me/workspace/mypackage/mypackage/__init__.pyc
...或进行不可编辑的安装时:
mypackage$ sudo -H pip install .
Processing /Users/me/workspace/mypackage
Installing collected packages: mypackage
Running setup.py install for mypackage ... done
Successfully installed mypackage-1.0.0
mypackage$ cd /tmp
tmp$ python -c 'import mypackage; print mypackage.__file__'
/usr/local/lib/python2.7/site-packages/mypackage/__init__.pyc