Amosplanet

Stay Hungry, Stay Foolish

Install Python 3.9.9 on Centos7

1. Download necessary dependency package
yum install -y libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel zlib gcc make libpcap-devel xz-devel gdbm-devel libxslt-devel libxml2-devel
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel zlib* libffi-devel readline-devel tk-devel
2. Download python3.9.9
wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz

If it posted error about wget, most probably wget has not been installed yet.

yum install wget
3. Uncompressed python3.9.9 and make install
tar -zxvf Python-3.9.9.tgz
cd Python-3.9.9
./configure
make&&make install
4. configure Env Varables so that python2/python3, pip can be distinguished
mv /usr/bin/python /usr/bin/python.bak   #删除以前python2.7的软连接
ln -s /usr/local/bin/python3 /usr/bin/python
mv /usr/bin/pip /usr/bin/pip.bak (如果报错说没有pip直接跳过)
以下为没有此文件或目录报错
ln -s /usr/local/bin/pip3 /usr/bin/pip
5. Confirm if Python and Pip have been installed successfully
python
exit()
pip -V
6. Install virtualenv and virtualenvwrapper

Installation Env.: Centos7

Reference: https://www.cnblogs.com/hszstudypy/p/11510933.html

a. Install virtualenv
pip3 install virtualenv
b. Install virtualenvwrapper
pip3 install virtualenvwrapper
c. Configure global varables

(1) find / -name virtualenvwrapper.sh

WORKON_HOME=~/Envs # Set virtualenv management directory, all virtual env. you will download in futre, will be stored here

(2) vi ~/.bashrc (Add contents below)

VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 #Assign python 解释器的本体(注意此路径随不同的linux环境改变而改变)
export WORKON_HOME=~/Envs
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
These shoulde be added at the end of text

(3) execute source ~/.bashrc and make it work

source ~/.bashrc
reboot 

(4) virtualenvwrapper instructions

1) Create virtual Environment

mkvirtualenv demo3

2) Look up virtual env.s

lsvirtualenv or workon

3) Start or switch virtual env.s

workon [env. name]

4) Exit out virtual env.s

deactivate

5) Delete virtual env.s

rmvirtualenv [Virtual env. name]

6) Look up virtual env.s packages

pip list

Leave a Comment

Your email address will not be published. Required fields are marked *