Rate This Document
Findability
Accuracy
Completeness
Readability

Installing Python

Python 3.9.9 is installed by default in openEuler 22.03 LTS SP3. However, TensorFlow 1.15.5 depends on Python 3.7.x. Therefore, you need to reinstall Python. This section describes how to install Python 3.7.5 using source code.

  1. Use PuTTY to log in to the server as the root user.
  2. Go to the compilation path for Python source code.
    cd /path/to/python
  3. Install Python source code compilation dependencies.
    yum install zlib-devel openssl-devel sqlite-devel xz-devel bzip2-devel libffi-devel
  4. Download the Python 3.7.5 source code to the server.
    1
    wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz --no-check-certificate
    
  5. Decompress the Python 3.7.5 source package and go to the decompressed directory.
    1
    2
    tar -zxvf Python-3.7.5.tgz
    cd Python-3.7.5
    
  6. Perform the configuration.
    1
    ./configure --prefix=/usr/local/python3.7.5 --enable-loadable-sqlite-extensions --enable-shared
    
    • --prefix: specifies the Python installation path. Change the path as required. /usr/local/python3.7.5 is used as an example.
    • --enable-shared: compiles the libpython3.7m.so.1.0 dynamic library and installs it in /usr/local/python3.7.5/lib/libpython3.7m.so.1.0.
    • --enable-loadable-sqlite-extensions: loads the libsqlite3-dev dependency.
  7. Perform the compilation.
    1
    make
    
  8. Perform the installation.
    1
    make install
    
  9. Configure Python 3 environment variables.
    1
    2
    export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
    export PATH=/usr/local/python3.7.5/bin:$PATH
    
  10. View the installed versions.
    1
    2
    python3 --version  
    pip3 --version
    

    If the correct versions are displayed, the installation is successful.

  11. Back up the original Python program and create a Python soft link.
    1
    2
    3
    4
    mv /usr/bin/python /usr/bin/python_bk
    mv /usr/bin/pip /usr/bin/pip_bk
    ln -s  /usr/local/python3.7.5/bin/python3 /usr/bin/python
    ln -s  /usr/local/python3.7.5/bin/pip3 /usr/bin/pip
    
  12. View the installed versions.
    1
    2
    python --version  
    pip --version
    

    If the correct versions are displayed, the installation is successful.

  13. Configure the pip repository and update pip.
    1
    2
    3
    pip3 config set global.index-url https://mirrors.huaweicloud.com/repository/pypi/simple
    pip3 config set global.trusted-host mirrors.huaweicloud.com
    pip3 install --upgrade pip