python3 pip3安装转到2.7

时间:2018-02-07 22:20:35

标签: python python-3.x pip

当我尝试使用pip3.6安装软件包(任何软件包)时,请不要使用正确的python版本。相反,他们进入2.7

$ pip3.6 install sklearn
Collecting sklearn
  Downloading sklearn-0.0.tar.gz
Collecting scikit-learn (from sklearn)
  Downloading scikit_learn-0.19.1-cp36-cp36m-manylinux1_x86_64.whl (12.4MB)
    100% |████████████████████████████████| 12.4MB 138kB/s 
Installing collected packages: scikit-learn, sklearn
  Running setup.py install for sklearn ... done
Successfully installed scikit-learn-0.19.1 sklearn-0.0
Target directory /usr/lib/python2.7/dist-packages/scikit_learn-0.19.1.dist-info already exists. Specify --upgrade to force replacement.
Target directory /usr/lib/python2.7/dist-packages/sklearn-0.0-py3.6.egg-info already exists. Specify --upgrade to force replacement.
Target directory /usr/lib/python2.7/dist-packages/sklearn already exists. Specify --upgrade to force replacement.

注意Target directory /usr/lib/python2.7/dist-packages/scikit中的python2.7,即使我使用的是pip3.6

当我尝试在python3.6中导入时,找不到包

$ python3.6
Python 3.6.1 (default, Feb  7 2018, 17:00:49) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sklearn'

pip3.6文件中提到了正确的python版本

$ cat /usr/local/bin/pip3.6
#!/usr/local/bin/python3.6

# -*- 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())

pip3.6似乎指向正确的python版本

$ pip3.6 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)

有关如何让pip3.6在正确的python文件夹中安装软件包的想法吗?

1 个答案:

答案 0 :(得分:1)

-t参数允许指定目标路径以安装需要的包。这最终起作用,但没有解决根本问题

python3.5 -m pip install scikit-learn -t /usr/lib/python3.5/