2、 Download the python source code package from the official website
3、 Unzip and install
4、 Modify the configuration file
First enter the directory decompressed in the previous step
5、 Start compiling and installing
6、 Configure shared library files
1 ) Set the shared library directory for all users
2 ) Refresh environment variables
7、 Test python
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
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)
2.2 Modify the default environment directory:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.6
export WORKON_HOME=~/.virtualenv
export PROJECT_HOME=~/.virtualenv/project_data
source /usr/local/bin/virtualenvwrapper.sh
2.3 Create a directory to store the virtual environment
mkdir ~/.virtualenv
2.4 Initialize
2.5 Basic usage: Create a virtual environment:
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
( test1) [root@redis test1]# lsvirtualenv
python3 #
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