Simple solution to multi-version python switching and multi-version pip correspondence
Check version number before changing
$ python -V Python 2.7.12
$ python2 -V Python 2.7.12
$ python3 -V Python 3.5.2
See many executable file paths for Python 3 through the following commands. Note / usr / bin / Python 3.5. Next, you need to create links
$ whereis python3 python3: /usr/bin/python3.5-config /usr/bin/python3.5m-config /usr/bin/python3.5m /usr/bin/python3 /usr/bin/python3.5 /usr/lib/python3 /usr/lib/python3.5 /etc/python3 /etc/python3.5 /usr/local/lib/python3.5 /usr/include/python3.5m /usr/include/python3.5 /usr/share/python3 /usr/share/man/man1/python3.1.gz
Look at python to get its executable path and delete it
$ which python /usr/bin/python
$ sudo rm /usr/bin/python
$ python ~bash: /usr/bin/python: No such file or directory
If you delete the above and enter the $python command, you will get an error because the system does not know how to execute it, and then we will create a new default link for it to python 3.5.
$ sudo ln -s /usr/bin/python3.5 /usr/bin/python $ python -V Python 3.5.2
This completes the modification of the default version. You can also modify Python 2 and python 3 in the same way.
In fact, after the above steps are executed, the default version of PIP is Python 3.5, and the same version of PIP 3 still corresponds to Python 3. Here we need to change the configuration file of pip2, otherwise we can no longer use pip2.
Check out the current pip and pip3 versions
$ pip -V pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
$ pip3 -V pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
However, the following error occurred when looking at pip2, because the configuration file has not been changed.
$ pip2 - V Traceback (most recent call last): File "/usr/bin/pip2", line 9, in <module> load_entry_point('pip==8.1.1', 'console_scripts', 'pip2')() File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 542, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2568, in load_entry_point raise ImportError("Entry point %r not found" % ((group, name),)) ImportError: Entry point ('console_scripts', 'pip2') not found
Open the'/ usr/bin/pip2'file in the error prompt and change the'#! / usr/bin/python' in the first line of the file to'#! / usr/bin/python 2'.
$ sudo vi /usr/bin/pip2
The original document reads as follows:
Then test that pip2 successfully corresponds back to version Python 2.7
$ pip2 -V pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
So far, it's all finished
Sometimes they make mistakes, mostly because they don't add sudo.
In the face of such problems, but after reading the article, it is still unsolved.
Comments or QQ: 781378815