Configure python3 environment on centos7 and

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

Configure python3 environment on centos7 and
CentOS 7 configure Python language development environment
Python and scrapy deployment in centos environment
Configure Ocserv on CentOS 6
Centos7 configure nodejs environment
Configure CentOS7 GPU environment
Install JDK and configure environment variables on Ubuntu 16.04
How to install and configure Elasticsearch on CentOS 7
How to install and configure Redis on CentOS 8
How to install and configure phpMyAdmin on CentOS 6
How to install and configure Owncloud on CentOS 8
How to install and configure Redmine on CentOS 8
Python introduction and environment installation
centos7 install python3 and ipython
Centos 6.10 reinstall python and yum
Centos6.5 install and configure mongodb
Configure swap space on CentOS7
CentOS7 install python3 and pip3
CentOS 6.9 compile and install python
CentOS 6 compile and install python 3
Centos7 deploys python3 virtual environment
How to install and configure NFS server on CentOS 8
Install and configure Mono production environment on Ubuntu Server
CentOS 7 configure Java language development environment
Install and configure keepalived under CentOS 5.9
Configure rsyslog log client on CentOS
CentOS 7 configure Ruby language development environment
CentOS + Python3.6+
CentOS7 compile and install L(A|N)MP environment
CentOS quickly install Python3 and pip3
How to install Python 3.8 on CentOS 8
Install Python3 and ansible under CentOS8
Build Nginx environment on Linux (CentOS)
Install Python virtual environment on Ubuntu 18.04
CentOS Minimal install and configure TIPS
Centos 7.5 python3.6
Install Python3 and Py under CentOS7
Install and configure FreeIPA in Centos7
Configure Nginx reverse proxy based on CentOS 7
Configure Nginx forward proxy based on CentOS 7
Centos-6.5 installation and deployment of LNMP environment
R&D: How To Install Python 3 on CentOS 7
Deploy Docker and configure Nginx in CentOS
Deploy python3 and nginx projects on ubuntu18.04
Install VMware Fusion and CentOS-7 on Mac
Some Centos Python production environment deployment commands
Centos6 install Python2.7.13
Centos7 install Python 3.6.
CentOS7 upgrade python3
CentOS install Python 3.6
Centos7 install Python2.7
Python and Go
Centos install Python3
Centos7 configure JDK
CentOS6.8 install python2.7
How to install and configure NATS on Ubuntu 16.04
VMware Fusion install CentOS7 and configure the network
How to install and use Docker on CentOS 7
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure GitLab on Ubuntu 18.04