为什么Python 3在我的Python 2.7包目录中查找包?

Mic*_*eyn 6 python pip python-3.x python-3.5

OS(Linux):Ubuntu 14.04.4 LTS(Trusty Tahr)

出于某种原因,我的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
Run Code Online (Sandbox Code Playgroud)

更多细节:

] 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']
>>>
Run Code Online (Sandbox Code Playgroud)

^^^ - 这似乎是正确的,并没有提到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
Run Code Online (Sandbox Code Playgroud)

它发现它是2.7发行版中的已安装软件包,并且未能安装其Python 3版本/usr/local/lib/python3.5/site-packages.

为了给混音添加更多​​混乱,我试着直接进入第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())
Run Code Online (Sandbox Code Playgroud)

更新:PYTHONPATH设置为/usr/local/lib/python2.7/dist-packages.这是上述问题的原因.感谢用户be_good_do_good帮助我弄清楚要转动哪些螺丝以使其正常工作.

be_*_*ood 5

PYTHONPATH 可能已设置为 2.7 分发包,这可能会导致此问题。