Create a python virtual environment on a linux server
background:
There are python2.7 and python3.6 versions on the linux server, and you need to install a higher version. Here we take python3.10.0 version as an example
Download python 3.10.0 version
wget /ftp/python/3.10.0/Python-3.10.
- Decompression
tar -zxvf Python-3.10.
- Go to the directory
cd Python-3.10.0
- Since the installation of python 3.10.0 requires that openssl be at least version 1.1.1, check the openssl version
openssl version
- If the openssl version does not meet the requirements, executing pip install in the virtual environment will report an error
- Therefore, you need to upgrade the openssl version first, please refer to:OpenSSL version upgrade on linux server
Check the location of openssl installation
find / -name "" 2>/dev/null find / -name "" 2>/dev/null find / -name "openssl" -type d 2>/dev/null
- Set environment variables
export LDFLAGS="-L/usr/local/openssl/lib" export CPPFLAGS="-I/usr/local/openssl/include"
Specify the openssl version at compile time
./configure --with-openssl=/usr/local/openssl --prefix=/usr/local/python310/
- Compilation
make
- Install
make install
Create a python virtual environment
mkdir ./venv310 /usr/local/python310/bin/python3.10 -m venv ./venv310
- Enter the python virtual environment
source ./venv310/bin/activate
- Check python version
python --version
Installation successfully! !
- Check whether the dependency can be downloaded successfully
pip install pytest
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.