The new installation environment python3

reference

When installing python3, do not overwrite the original python2 environment. Because some of the program is dependent on the environment 2, such as yum. Direct coverage will affect the environment.
Most preferably python3 compiled and installed, the instruction is executed as a command python3 difference python (2) to the next instruction.

1. install dependencies

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

If this step is not done well, the back will affect pip install installation feature

2. Download and install python3

Installation location depends on personal preference, assuming /usr/local/python3

  • download
# 这个指令执行位置即下载位置
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
  • Decompression
tar -zxvf Python-3.6.1.tgz

3. Compile install

After entering the decompression directory

cd Python-3.6.1

Compiler installation, - after installation location prefix path

./configure --prefix=/usr/local/python3     
make && make install

If traveling behind the implementation of mistake, the lack of a display module, to re-execute the [installation] compilation step

4. Create a soft python3

This step is to distinguish and python python3
this step, the next instruction python3 later, will not be executed if an error:python3: command not found

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

If you recompile installed python3 changed the installation location, perform this step errors after the installation finished: ln: python3: file exit
execute:

ln -snf /usr/local/python3/bin/python3 /usr/bin/python3

Parameter -snfrepresents coverage

5. / usr / local / python3 / bin added PATH

This file boot execution

# vim ~/.bash_profile

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH

Compile file

source ~/.bash_profile

The installation is complete, check python3, pip3 execution is valid.
If pip3 invalid, create a soft link at:

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

6. Resolve Missing module error

Check that pip3 normally installed modules:

pip3 install paramiko

The most common error is the lack of ssl module.

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

This is due to the time-dependent environment in front of the installation do not lack ssl dependence.
Then fill install this module

yum install openssl
yum install openssl-devel

After the installation finished third step to re-execute compile and install python3 environment, the newly installed modules are compatible with the installation environment into python3

cd Python-3.6.1
./configure --prefix=/usr/local/python3     
make && make install

Refer to the original there are missing setuptoolsmodules and installation pipof modules, there are related problems encountered point to go see the line.

The basic idea:
to see it being given written inside what is missing module, go to make up what the module is installed.
To re-execute the installation finished third step compile and install python3 environment, will be compatible with the newly installed modules into the installation environment python3

Guess you like

Origin www.cnblogs.com/JanSN/p/11014080.html