OS(Linux的):Ubuntu 14.04.4 LTS(忠實的塔爾羊)爲什麼Python 3在我的Python 2.7包目錄中查找包?
出於某種原因,我的Python 3.5.2正在尋找到Python 2.7包目錄,而不是它自己:
] python3 -m ensurepip
Ignoring indexes: https://pypi.python.org/simple
Requirement already satisfied (use --upgrade to upgrade):
setuptools in /usr/local/lib/python3.5/site-packages
Requirement already satisfied (use --upgrade to upgrade):
pip in /usr/local/lib/python2.7/dist-packages
更多細節:
] python3
Python 3.5.2 (default, Jul 29 2016, 09:41:38)
[GCC 6.1.1 20160511] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import site; site.getsitepackages()
['/usr/local/lib/python3.5/site-packages']
>>>
^^^ - 這似乎是正確的,並沒有提及任何關於2.7包目錄。
它看起來應該只看在/usr/local/lib/python3.5/site-packages
,但由於某種原因,它也在尋找/usr/local/lib/python2.7/dist-packages
它沒有業務在尋找。
例如,看看會發生什麼,當我嘗試安裝psycopg2
作爲一個Python 3模塊:
] python3 -m pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade):
psycopg2 in /usr/local/lib/python2.7/dist-packages
據發現它在2.7分發的安裝包,並沒有安裝Python的第3版在/usr/local/lib/python3.5/site-packages
。
要添加更多的混亂混進去,我試着去直pip 3,但無濟於事:
] pip3 install psycopg2
Requirement already satisfied (use --upgrade to upgrade):
psycopg2 in /usr/local/lib/python2.7/dist-packages
] cat `which pip3`
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
更新:PYTHONPATH
設置爲/usr/local/lib/python2.7/dist-packages
。這是上述問題的原因。信貸去用戶be_good_do_good幫助我找出哪個擰讓事情工作,因爲他們應該。
您可以發佈您的PATH值和PYTHONPATH價值 –
@be_good_do_good在想着同樣的,也許有一個手動添加2.7站點包路徑 – rll
你也應該張貼sys.path'的'值。您也可以在其中一個搜索到的位置使用'.pth'文件。 'sys.path'應該說明這一點。它也許值得在詳細模式('python -v')下運行以查看從哪個模塊導入。 – theorifice