首先,建立 python 虚拟环境 test_env:
python3 -m venv test_env
# 激活虚拟环境
source ./test_env/bin/activate # linux
venv/Scripts/activate # windows
# 停止虚拟环境
deactivate # windows / linux
然后,安装所需的依赖包。
pytorch 会麻烦一点,我们先装 pytorch(详见 pytorch.org):
# cpu 版
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
再装其他包,直接使用 requirements.txt:
# 如果安装太慢,需要 pip 换源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
# pip 使用 requirements.txt
pip install -r requirements.txt
requirements.txt 的格式:
gym>=0.21
# torch>=1.11
numpy>1.16.0 # https://github.com/numpy/numpy/issues/12793
pandas>=0.24.2
scipy>=1.4.1
scikit-learn>=0.21.2
matplotlib>=3.1.0
wandb>=0.12.0
jupyter>=1.0.0
h5py>=2.9.0
pygame>=2.1.0
typing_extensions>=4.0
cloudpickle
importlib-metadata~=4.13
pillow
tqdm
isort>=5.0
rich
psutil
flake8>=3.8
black
pytest
pytest-cov
pytype
opencv-python
openpyxl
func_timeout
标签:requirements,python,pytorch,虚拟环境,pip,txt,搭建
From: https://www.cnblogs.com/moonout/p/16997694.html