简体   繁体   中英

Why pip3 install in python2 sitepackages

First I use

Python 3.6.5
Python 2.7.14
and mac.

In my case, I just download module like numpy (for example, and other's same) when i use pip3 it said like.. 在此处输入图片说明

and pip is same.

but when I use it, in python3 在此处输入图片说明

In python2 , It working well... 在此处输入图片说明

How can I fix it?

It seems that pip3 refers to Python-2.7's pip module or any other version of Python-3 that you have installed on your machine. However, you can install packages directly using the intended Python version. You'd need to just use -m option.

python3.6 -m pip install numpy

Another option is to changing the source path that pip3 refers to. You can do this by finding the path of Python-3.6's pip and just bind it to pip3 alias.

Find the absolute path of the python3 interpreter with a command like this:

$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python

Your path may be something different, of course. Copy that line to your clipboard.

Edit the pip3 script, which was installed using incorrect interpreter. Something like this:

vi $(which pip3)

You might need to use sudo here, but try it first without. The first line will be something like:

#!/Library/Frameworks/Python.framework/Versions/2.7/bin/python

Change it to the path found in the previous step, eg

#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python

Save the pip3 file and exit. This should be sufficient to associate pip3 with the correct environment. Check and verify the result with pip3 --version . Now pip3 install numpy should work as expected.

这对我有用:

python3 -m pip install -U --force-reinstall pip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM