Installation Daquan

Original link: https://www.codewoody.com/posts/16233/

1 Python3 installation method

1.1 Python 3 installation

Reference: https://ift.tt/84SBdkP

The installation instructions are as follows:

 1
2
3
 sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install -y python3.10

In addition to installing Python3 itself, you also need to install Python-pip

 1
 sudo apt install -y python3-pip

1.2 Pip domestic mirror configuration

Reference link: https://ift.tt/K0jfRDw

We can specify the source address in a single Pip command via the -i option, for example:

 1
 pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

If you want to do global configuration for the current user, you need to create the directory ~/.pip and create the file (if it doesn’t exist) ~/.pip/pip.conf

 1
2
3
4
 [global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

You can view the current mirror configuration with the pip3 config list command:

 1
2
3
 $ pip3 config list
global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'
install.trusted-host='https://pypi.tuna.tsinghua.edu.cn'

1.3 Python3 virtual environment

Reference link: https://ift.tt/UQF4GRd

Install virtualenvwrapper

 1
 sudo pip3 install virtualenvwrapper

This package will also be installed with virtualenv.

Then we need to go to the current shell’s configuration file ( .zshrc or .bashrc , depending on the type of shell you use) and add:

 1
2
3
 export VIRTUALENVWRAPPER_PYTHON=$(which python3)
#Open terminal automatically enable
source /usr/local/bin/virtualenvwrapper.sh

Use the mkvirtualenv to create a virtual environment and set the Python version with the --python option:

 1
 mkvirtualenv test --python=python3

1.4 Frequently Asked Questions

  1. ModuleNotFoundError: No module named ‘distutils.cmd’ error occurs when Pip is installed,

Install dependencies:

 1
 sudo apt install -y python3-distutils

If multiple Python versions exist, more detailed dependencies can be specified:

 1
 sudo apt install -y python3.10-distutils

This article is reproduced from: https://www.codewoody.com/posts/16233/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment