Centos7 deploys python3 virtual environment

  1. Deploy Python3 on CentOS
    1、 Install dependencies

yum -y install zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel curl epel-release gcc

2、 Download the python source code package from the official website

curl -o python3.6.tgz https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

3、 Unzip and install

tar -xf Python-3.6.5.tgz -C /usr/local/src/

4、 Modify the configuration file
First enter the directory decompressed in the previous step

cd /usr/local/src/Python-3.6.5/

Execute the following command to cancel the comment at the corresponding position#

sed -ri 's/^#readline/readline/' Modules/Setup.dist

sed -ri 's/^#(SSL=)/\1/' Modules/Setup.dist

sed -ri 's/^#(_ssl)/\1/' Modules/Setup.dist

sed -ri 's/^#([\t]*-DUSE)/\1/' Modules/Setup.dist

sed -ri 's/^#([\t]*-L$(SSL))/\1/' Modules/Setup.dist

5、 Start compiling and installing

. /configure --enable-shared

- - enable-shared specifies the installation of shared libraries, which will be used when using other software that requires python to be called, such as when using mod_wgsi to connect Apache and python#

make -j 2 && make install

- j cpu core number#

6、 Configure shared library files

1 ) Set the shared library directory for all users

cd /usr/local/src/Python-3.6.5/

cp libpython3.6m.so.1.0 /usr/local/lib64/

cp libpython3.6m.so.1.0 /usr/lib/

cp libpython3.6m.so.1.0 /usr/lib64/

2 ) Refresh environment variables

source /etc/profile

7、 Test python

python3

Python 3.6.5 (default, Mar 29 2019, 17:13:23)
[ GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.

exit()

8、 Test pip3

pip3 -V

pip 9.0.3 from /usr/local/lib/python3.6/site-packages (python 3.6)

Second, use the third-party virtual tool Virtualenvwrapper
2.1 Installing virtualenvwrapper provides a series of commands to make working with virtual environments much more enjoyable. It puts all your virtual environments in one place. More importantly, you only need to run a command to enter your virtual environment, you don't need to install it in a directory like the virtual environment before (make sure virtualenv is installed)

pip3 install virtualenvwrapper

2.2 Modify the default environment directory:

cat ~/.bashrc

. bashrc

User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

Source global definitions

if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

Specify interpreter

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.6

This can customize the virtual environment storage directory

export WORKON_HOME=~/.virtualenv

Project storage directory, you need to create it yourself

export PROJECT_HOME=~/.virtualenv/project_data

Automatically load virtualenvmrapper

source /usr/local/bin/virtualenvwrapper.sh

2.3 Create a directory to store the virtual environment
mkdir ~/.virtualenv

This directory should have the same value as the WORKON_HOME variable above#

2.4 Initialize

source ~/.bashrc

2.5 Basic usage: Create a virtual environment:

mkvirtualenv test

2.6 Exit the virtual environment:
deactivate
[ root@redis ld.so.conf.d]# workon test
( test) [root@redis test]# deactivate

2.7 Enter the virtual environment:
[ root@redis ld.so.conf.d]# workon
python3
test
[ root@redis ld.so.conf.d]# workon test
( test) [root@redis test]#

2.8 Create project:
( test) [root@redis test]# mkproject test1
Using base prefix '/usr/local'
New python executable in /root/.virtualenv/test1/bin/python3.6
Also creating executable in /root/.virtualenv/test1/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /root/.virtualenv/test1/bin/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/test1/bin/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/test1/bin/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/test1/bin/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/test1/bin/get_env_details
Creating /root/.virtualenv/project_data/test1
Setting project for test1 to /root/.virtualenv/project_data/test1
( test1) [root@redis test1]# ls
( test1) [root@redis test1]# ls /root/.virtualenv/project_data/
test test1

2.9 List the available operating environments:

( test1) [root@redis test1]# lsvirtualenv
python3 #

test1

test

2.10 List the packages installed in the current environment:
lssitepackages:
( test1) [root@redis test1]# lssitepackages
easy_install.py pip-19.0.3.dist-info pycache setuptools-40.8.0.dist-info wheel-0.33.1.dist-info
pip pkg_resources setuptools wheel

2.11 Create a temporary operating environment:
mktmpenv
[ root@redis test1]# mktmpenv
Using base prefix '/usr/local'
New python executable in /root/.virtualenv/tmp-4aa130f4957b04a/bin/python3.6
Also creating executable in /root/.virtualenv/tmp-4aa130f4957b04a/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /root/.virtualenv/tmp-4aa130f4957b04a/bin/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/tmp-4aa130f4957b04a/bin/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/tmp-4aa130f4957b04a/bin/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/tmp-4aa130f4957b04a/bin/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/tmp-4aa130f4957b04a/bin/get_env_details
This is a temporary environment. It will be deleted when you run 'deactivate'.

2.12 Delete when the temporary environment exits:
( tmp-4aa130f4957b04a) [root@redis tmp-4aa130f4957b04a]# deactivate
Removing temporary environment: tmp-4aa130f4957b04a
Removing tmp-4aa130f4957b04a...

2.13 Delete the virtual environment:
rmvirtualenv
[ root@redis .virtualenv]# workon
python3
test1
test
[ root@redis .virtualenv]# rmvirtualenv python3
Removing python3...
[ root@redis .virtualenv]# workon
test1
test

2.14 Install the package in a virtual environment
All virtual environments are under ~/.virtualenv/project_data, which are independent and do not affect each other. To install the package in the virtual environment, you can use pip without root permission
[ root@redis .virtualenv]# workon test
( test) [root@redis test]# pip install selenium
Collecting selenium
Downloading https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl (904kB)
100 % |████████████████████████████████| 911kB 15kB/s
Collecting urllib3 (from selenium)
Downloading https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl (118kB)
100 % |████████████████████████████████| 122kB 11kB/s
Installing collected packages: urllib3, selenium
Successfully installed selenium-3.141.0 urllib3-1.24.1

( test) [root@redis test]# pip list
Package Version


pip 19.0.3
selenium 3.141.0
setuptools 40.8.0
urllib3 1.24.1
wheel 0.33.1
( test) [root@redis test]# deactivate

Switch to env_python3.6 to view "No selenium package":
[ root@redis test]# workon test1
( test1) [root@redis test1]# pip list
Package Version


pip 19.0.3
setuptools 40.8.0
wheel 0.33.1

Recommended Posts

Centos7 deploys python3 virtual environment
Python virtual environment: Ubuntu16.04
CentOS + Python3.6+
Centos 7.5 python3.6
Install Python virtual environment on Ubuntu 18.04
[python] python virtual environment construction & GPU environment
CentOS 7 configure Python language development environment
Centos6 install Python2.7.13
Centos7 install Python 3.6.
CentOS7 upgrade python3
CentOS install Python 3.6
Centos7 install Python2.7
Python and scrapy deployment in centos environment
Centos install Python3
Detailed usage of Python virtual environment venv
CentOS6.8 install python2.7
Python: Virtual Environment-Ubuntu16.04
Some Centos Python production environment deployment commands
Ubuntu20.04 install Python3 virtual environment tutorial detailed explanation
Docker deploys Python projects
Centos 6.4 python 2.6 upgrade to 2.7
CentOS6.7 build LNMP environment
CentOS7.3.1611 deploys k8s1.5.2 cluster
Centos 6.4 python 2.6 upgrade to 2.7
Hadoop environment construction (centos7)
Centos7.6 build LNMP environment
Centos source installation Python3
CentOS 7 deploys RabbitMQ service
Centos6.9 install npm environment
CentOS7 deploys NFS service
Centos7 deploys Kubernetes cluster
Centos7 configure nodejs environment
CentOS Python Java installations
CentOS7 deploys k8s cluster
Configure CentOS7 GPU environment
CentOS 7 build LNMP environment
How to create a Python virtual environment in Ubuntu 14.04
[CentOS environment deployment] Java7/Java8 deployment under CentOS
Python introduction and environment installation
Build docker environment under Centos6.5
CentOS upgrade python2 to pyth
centos7 install python3 and ipython
Install python environment under Linux
SkyWalking study notes (CentOS environment)
ubuntu sets python2.5 environment variables
Centos7 set up GitBook environment
CentOS 7.2 deploy Node.js development environment
CentOS install nginx+tomcat+java+mysql operating environment
Centos 6.10 reinstall python and yum
Linux CentOS 7 virtual machine clone
Centos configure multiple virtual IP
CentOS deploys Harbor mirror warehouse
CentOS7 install python3 and pip3
Centos6 set up GitBook environment
CentOS 6.9 compile and install python
Centos6 install python3 pip3 ipython3
CentOS environment installation of Docker
Centos7.4 environment installation lamp-php7.0 tutorial
ubuntu offline installation python environment
Centos configure multiple virtual IP
CentOS8 deploys LNMP environment to compile and install mysql8.0.29 tutorial details