5. Python venv

Create a venv in directory .venv

$ python -m venv .venv

Activate the venv:

$ . .venv/bin/activate

Set site configurations:

$ pip config set --site global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Writing to /home/ubuntu/.venv/pip.conf

Caution

Do not forget --site, or the user config file would be modified if there is not the site config file. Check the config files by:

$ pip config debug
env_var:
env:
global:
  /etc/xdg/pip/pip.conf, exists: False
  /etc/pip.conf, exists: False
site:
  /home/ubuntu/.venv/pip.conf, exists: True
    global.index-url: https://pypi.tuna.tsinghua.edu.cn/simple
user:
  /home/ubuntu/.pip/pip.conf, exists: False
  /home/ubuntu/.config/pip/pip.conf, exists: True