我使用了很多系统,这些系统被开发人员“遵循他们在互联网上找到的指示”所破坏。您pip
和您使用python
的路径/站点程序包不同,这是非常普遍的。因此,当我遇到奇怪的事物时,我首先要做的是:
$ python -c 'import sys; print(sys.path)'
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']
$ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
那是一个快乐的系统。
下面是一个不愉快的系统。(或者至少是一个幸福无知的系统,导致其他人感到不高兴。)
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
$ python -c 'import sys; print(sys.path)'
['', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']
$ which pip pip2 pip3
/usr/local/bin/pip
/usr/local/bin/pip3
很不高兴,因为pip
(python3.6和)正在使用/usr/local/lib/python3.6/site-packages
while python
是(python2.7和)正在使用/usr/local/lib/python2.7/site-packages
当我要确保将要求安装到正确的 python时,请执行以下操作:
$ which -a python python2 python3
/usr/local/bin/python
/usr/bin/python
/usr/local/bin/python2
/usr/local/bin/python3
$ /usr/bin/python -m pip install -r requirements.txt
您听说过,“如果它没有损坏,请不要尝试对其进行修复。” DevOps的版本是“如果您没有破坏它并且可以解决它,请不要尝试对其进行修复。”
--no-index
它甚至不看PyPI?