简体   繁体   中英

Python3.5 is installed but pip3 points to python3.6

Python3.5 is installed on my machine

$ python3 --version

Python 3.5.0

However, the pip3 command points to python3.6, which means:

$ pip3 --version

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

Therefore, all packages that I install with pip3 install xxxxx cannot be used by my python3.5 interpreter. They are obviously installed to python3.6, but I've never installed python3.6 on my machine.

The only walkaround that I can think of, is to use python3 -m pip to replace the pip3 that I want. This may work as shown below:

$ python3 -m pip --version

pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (python 3.5)

But it's really stupid. How to change the default destination of 'pip3' back to Python 3.5? ie How to make pip3 literally install packages for python3.5?

You will need to change your environment variables.

You can do that through the python interactive interpreter since python has a module to change environment variables.

So fire up the IDLE shell and enter these two commands:

>>> import sys
>>> sys.path

You should see an output similar to the following (This is from a Windows computer):

['', 'C:\\python36', 'C:\\python36\\Lib\\idlelib', 'C:\\Python36\\python36.zip', 
'C:\\Python36\\DLLs', 'C:\\Python36\\lib', 'C:\\Python36', 'C:\\Python36\\lib\\site-packages']

Delete the entry similar to '/Python36/lib/site-packages' for Linux/Mac OS X users, or for Windows users, 'C:\\\\Python36\\\\lib\\\\site-packages' in the array.

Be very careful not to delete anything else. Try simply printing the index to make sure it is the right one.

Once you have finished this step, reboot your computer to ensure the changes are made.

Test that it worked by checking the pip version on a terminal or command prompt.

If it works, you're done! However, some of you may see an error saying pip3 was not found. In that case, do back to the shell and (after reimporting sys) append the directory of python 3.5 followed by /lib/site-packages .

Reboot your computer again and test that it worked. If it didn't you might need to reinstall python 3.5 to get it to work. However, if you fallowed the steps correctly that is very rare.

I hope this answer is useful!

Download the bootstrap script for pip from pypa, and then install it with your Python 3.5 interpreter

$ wget https://bootstrap.pypa.io/get-pip.py
$ python3 get-pip.py

This will then install pip into your python3 installation.

You may even already have it, and you can double-check that by looking in:

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/Scripts

You can try to find it in the directory with the find command
and then you can try to backup the old pip command and replace it with the new:

$ PIP_3_5=$(find /Library/Frameworks/Python.framework/Versions/3.5/lib/python‌​3.5 -name pip)
$ mv $(which pip) $(which pip)3.6
$ alias pip=$PIP_3_5

Keep in mind that I haven't tested these commands as I'm on Windows, but if my memory is correct then that should do it...

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