Compiling and Installing Python
The following describes how to install Python 3.10.0 as the root user. Before compilation, ensure that the system time matches the current time to prevent an infinite loop during Python compilation and installation.
- Install the dependencies required for source code compilation.
- Ubuntu:
apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev
- openEuler:
dnf install -y gcc make python-devel zlib-devel ncurses-devel gdbm-devel nss-devel openssl-devel readline-devel libffi-devel sqlite-devel
- Ubuntu:
- (Optional) Install the wget tool. If it has been installed in the environment, skip this step.
- Ubuntu:
apt update && apt install -y wget
- openEuler:
dnf update && dnf install -y wget
- Ubuntu:
- Download the source package of Python 3.10.0 to any directory of the installation environment.
wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz
- Go to the download directory and extract the source package.
tar -zxvf Python-3.10.0.tgz
- Go to the decompressed folder and run the following configuration, build, and installation commands:
cd Python-3.10.0 ./configure --prefix=/usr/local/Python3.10.0 --enable-loadable-sqlite-extensions --enable-shared make make install
Parameter description:
--prefix specifies the Python installation path. You can change it as required.
- Set the Python 3.10.0 environment variables. You can set permanent environment variables by modifying the ~/.bashrc file as follows:
- Run the vi ~/.bashrc command to open the .bashrc file and add the following content:
export LD_LIBRARY_PATH=/usr/local/Python3.10.0/lib:$LD_LIBRARY_PATH export PATH=/usr/local/Python3.10.0/bin:$PATH
- After saving the file, run the source ~/.bashrc command for the modification to take effect immediately.
- Run the vi ~/.bashrc command to open the .bashrc file and add the following content:
- After the installation is complete, run the following commands to check the installation version. If the required version information is displayed, the installation is successful.
python3 --version pip3 --version
- Configure the pip repository.
- Run the following command as the installation user of the software package:
cd ~/.pip
If the system displays a message indicating that the directory does not exist, run the following commands to create a directory and access it:
mkdir ~/.pip cd ~/.pip
- Edit the pip.conf file.
Run the vi pip.conf command to open the pip.conf file and edit the file as follows.
[global] # The Huawei repository is used as an example. Replace it based on the actual situation. index-url = https://mirrors.huaweicloud.com/repository/pypi/simple trusted-host = mirrors.huaweicloud.com timeout = 120
- Run the :wq! command to save the file and exit.
- Run the following command as the installation user of the software package:
Parent topic: Appendixes