python version control

Keywords: Python Pycharm sudo

Reference article: Thanks to Blogger 1
There are three levels of python version control: system level, folder level and pycharm level

system level

First, check the number of python versions installed in the system:

  • Method 1:
zht@zht0:~$ ls /usr/bin/python*
/usr/bin/python
/usr/bin/python2
/usr/bin/python2.7
/usr/bin/python2.7-config
/usr/bin/python2.7-dbg
/usr/bin/python2.7-dbg-config
/usr/bin/python2-config
/usr/bin/python2-dbg
/usr/bin/python2-dbg-config
/usr/bin/python3
/usr/bin/python3.5
/usr/bin/python3.5m
/usr/bin/python3m
/usr/bin/python-argcomplete-check-easy-install-script3
/usr/bin/python-config
/usr/bin/python-dbg
/usr/bin/python-dbg-config

See that there are both python2.7 and python3.5

  • Method two:
zht@zht0:~$ update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.5

The second method will only appear after the settings described in this article, so it is normal to use it before setting.

At present, if you use method 1 to check that there are at least two versions of Python folder, that is to say, multiple versions of Python have been installed in the system. You can do the next step: add python2.7 and python3.5 to the python list and set their default priority

zht@zht0:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode  
zht@zht0:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python (python) in auto mode  

Here, set the priority of Python 3.5 to 2, and the priority of Python 2.7 to 1. Note that 2 > 1, so by default, the system is already Python 3.5 (my previous is Python 2.7)
Finally, you can switch the python version

There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.5   2         auto mode
* 1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.5   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 

Just input the corresponding number

Virtual level

This article is better, but there is one point source deactivative. I always prompt that there is no such command, but it does not seem to affect the use,
Thank you blog 2

pycharm internal modification

File > Settings > Python interpreter can be modified

Posted by pob123 on Thu, 02 Apr 2020 19:34:11 -0700