As an experience, record the process of Python environment maintenance on CentOS.
For stability, use the latest version upgrade as much as possible.
At the moment, Python 3.9 is out, but I think 3.8.6 is more stable, so I will use it.
Since the version of the package managed by Linux itself is low, I think that Conda and others are troublesome, so I use the method of compiling from the source code.
First, install various tools for development. If you omit it, you may have problems with Python and pip.
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel
Next, get the Python source code. Find it on the Python site (https://www.python.org/downloads/) and download tgz.
Then run as root.
tar -zxvf Python-3.8.6.tgz
cd Python-3.8.6
./configure prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3.8
ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3.8
Finally, / usr / bin / python3
and / usr / bin / pip3
link to the previous link file. If you already have an older version, you have no choice but to delete it and recreate it.
Recent versions like Python 3.8.6 have a part called venv, which I think is good enough.
/usr/bin/python3 -m venv venv
The operation is as follows.
source venv/bin/activate || exit 1
python3 [PATH_OF.PY]
deactivate
Requirements.txt is required for projects that use third-party packages.
source venv/bin/activate || exit 1
#If you use a mirror, accompany it:-i "mirror_url"
pip3 install -r requirements.txt || exit 2
deactivate
Recommended Posts