We know that the configuration method for multi-version coexistence under Windows is to change the name of the executable file and configure environment variables.
The principle of configuration in Linux is similar. The idea is to generate soft links and configure them to environment variables.
Before configuration, python2.7 and python3.6 were installed in my Ubuntu. And the default input python uses python2.7
I need to configure to python3, just need to perform the following steps.
1. Find the location of the soft link'python' that currently represents python2.7 and delete it.
2. Find the execution file of python3.6 and generate a soft link to the environment variable.
As shown below:
Note: root privileges are required.
code show as below:
Find python location
1 |
|
Delete soft link
1 |
|
View environment variables
1 |
|
Generate python3 soft link to environment variable
1 |
|
------------------------------------------------------------------------------------------------------------------------
CentOS 7.2 installs python2.7.5 by default because some commands use it, such as yum, which uses python2.7.5.
It can be seen that the executable file is in the /usr/bin/ directory, switch to this directory and execute the ll python* command to view
tar xf Python-3.7.3.tgz
//Configure installation information
cd Python-3.7.3
./configure --prefix=/usr/local/python3/
//**Error: configure: error: no acceptable C when installing Python Compiler found in $PATH error
Because there is no gcc, it can be solved by installing gcc: yum install gcc
//compile
make && make install
Question 1: Configure: error: no acceptable C compiler found in $PATH error when installing Python
Solution: Because there is no gcc, it can be solved by installing gcc: yum install gcc
Question 2: An error occurred during make && make install: zipimport.ZipImportError: can't decompress data; zlib not available
Solution: yum -y install zlib*
yum install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev 3 xz-utils tk-dev
问题3:make && make install时错误: ModuleNotFoundError: No module named ‘_ctypes’
solve:
yum -y groupinstall "Development tools"
yum install libffi-devel -y
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
Configure environment variables
Create a new file
vim /etc/profile.d/python3.sh
export PATH=$PATH:/usr/local/python3/bin/
Execute the following command
export PATH=$PATH:/usr/local/python3/bin/
Verify
python3