The default python version of centos7 is 2.7, and the current mainstream python version is 3.6 or 3.7. The yum package manager of centos is based on python2, so it cannot be deleted directly. At the same time, the python environment version must be configured as python3 version, and the two versions need to coexist. At that time, ubuntu 16 or 18 was a better choice, but unbuntu is prone to update crashes, which is not as stable as centos.
One, configure python3 environment and pip
First confirm the centos7 version
hostnamectl
cat /etc/redhat-release
Then confirm the python version and execution path
which python
python -V
It can be seen that the executable file is in the /usr/bin/ directory, switch to this directory for execution
cd /usr/bin/&& ll python*
python points to python2.7
Because we want to install the python3 version, so python should point to python3. Currently python3 is not installed, please backup first, install related packages before backup, for downloading and compiling python3
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
You can’t ignore related packages. I didn’t install readline-devel before, so I can’t use the up, down, left, and right keys of the keyboard to execute python mode;
Then backup
mv python python.bak
Then, go to the official website to download the compiled package. This time python3.6 is installed, but the latest python3.7 is not used.
wget
tar -xvJf Python-3.6.2.tar.xz
cd Python-3.6.2
Then execute compile and install
. /configure prefix=/usr/local/python3
make && make install
After installation, there will be python3 in the /usr/local/ directory
So we can add the soft link to the execution directory /usr/bin
ln -s /usr/local/python3/bin/python3 /usr/bin/python
You can see that the soft chain is created
Test the installation is successful, execute
python -V see if the output is the version of python3
Execute python2 -V to see the version of python2
Because the python2 version is required to execute yum, we also need to modify the configuration of yum and execute:
vim /usr/bin/yum
Change #! /usr/bin/python to #! /usr/bin/python2
Similarly, the #! /usr/bin/python in the vim /usr/libexec/urlgrabber-ext-down file should also be modified to #! /usr/bin/python2
In this way, the python3 version is installed; at the same time python2 also exists
python -V version 3
python2 -V version 2
At this time, we also need to install pip to download and manage third-party modules and packages
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6
python setup.py build
python setup.py install
Set soft link
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
Enter pip -V to view the pip version, and the correct version will be displayed if the installation is successful
At the same time, configure pip domestic sources to increase download speed
mkdir ~/.pip && touch ~/.pip/pip.conf
vim ~/.pip/pip.conf
The content is as follows
[ global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[ install]
trusted-host=mirrors.aliyun.com
Two, install visual studio code for linux
Do not use graphical desktop, do not use ide to write python on linux, it is self-abuse!
Visual studio code is an ide produced by Microsoft, supports python, supports many languages, but does not support java
Centos is installed by rpm package, the installation document refers to the official manual
https://code.visualstudio.com/docs/setup/linux#_rhel-fedora-and-centos-based-distributions
First configure yum warehouse, only 64-bit version
sudo rpm --import
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
Then use yum to install
yum check-update
sudo yum install code
After installation, enter the code directly on the command line to use
You can confirm the installation and installation path
The visible program is installed in /usr/share/code
But this IDE does not support the use of root, you must switch to an ordinary user with a user directory to execute
Switch user identity, execute, it is very likely to report an error, prompting that the NSS component version is lower than the minimum requirement
At this point, you need to follow the new component
sudo yum install nss
At the same time, it will prompt that there is no libdus-1.so.3, at this time you need to download the dbus-libs package
yum install dbus-libs
At this point, you can find that vs code has been installed in the application-programming, click to execute
At this time, it is the English version, we need to install the Chinese plug-in, as shown below
Click install, then the Chinese interface
Then we install python extension and python support
Then create a new file, the file ending in .py, test
Press F5 to execute
For the need to support pep8 format typesetting support, vs code executes right-click to format the document, and the plug-in support is automatically downloaded
Regarding the use of vs code, there are many on the Internet, and it takes some time to explore
Recommended Posts