the Python version that comes with the server is mostly 2.X, and some system applications rely on the default python environment. But sometimes you need to use python3, in order not to conflict with the python Environment of the system , install the new Python3 Version and use the virtual environment. This article is to share with youCentos7 under installation Python3 with theVirtual Environmentsrelated content, come together to look at it, hope to everyoneLearningpythonhelpful.
Installation Preparation
Install the dependent packages first
Yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel Tk-devel gcc make
then, download the corresponding version of the Python installation package, which you can use
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
download directly to the server, or you can download it to this computer and upload it to Linux.
here, I have put Python-3.6.4.tgz downloaded to the server /app/ directory.
python3 installation
# Unzip
TAR-ZXVF python-3.6.4.tgz
# Enter the extracted directory
CD Python-3.6.4
# Compile (prefix indicates the path of installation, I install it here in /usr/local )
./configure--prefix=/usr/local/python-3.6.4
# Installation
Make && make install
Installation error occurs, usually due to the lack of packages, install the corresponding package, recompile installation.
then execute /usr/local/python-3.6.4/bin/python3 if there is no error, the python3 installation is complete.
Create a soft connection for Python3 (the file name of the soft connection is not python, because python has pointed to the python2.7 )
Ln-s/usr/local/python-3.6.4/bin/python3/usr/bin/python3
creating a soft connection for PIP3
Ln-s/USR/LOCAL/PYTHON-3.6.4/BIN/PIP3/USR/BIN/PIP3
you can then use the Python3 and pip3 commands directly.
installing the PYTHON3 virtual environment
Create a virtual environment under the ~/py3/directory
CD ~/py3/# Enter the py3 directory (new if not present)
Python3-m venv. # Create a virtual environment under the current directory
SOURCE Bin/activate # activates the virtual environment
the leftmost appears (PY3) , indicating that it has entered Python3 virtual Environment.
you can then use the Python and pip commands directly.
Source: Network
How do I install python3 and virtual environments under CENTOS7?