Python搭建虚拟环境并安装依赖

2024-08-02

#!/bin/bash
path_dir=$(dirname $(readlink -f "$0"))
while read line;
do
  eval "$line"
done < $path_dir/config
$path_dir/$python/bin/python3 -m venv $path_dir/$venv //创建虚拟环境
source $path_dir/$venv/bin/activate         //使虚拟环境生效
pip install --no-index --find-links=$path_dir/$packages -r $path_dir/$requirements //安装依赖


创建虚拟环境

python -m venv testenv


激活虚拟环境

windows

testenv\Scripts\activate


linux or mac

source testenv/bin/activate


退出虚拟环境

deactivate