不同的项目使用不同的环境,可以有效防止各种包、库版本的不兼容,
本人在项目中使用pipenv管理环境
1、安装pipenv
pip install pipenv
2、进入工程目录,创建虚拟环境
注意:pipenv会根据系统默认的python版本创建虚拟环境,所有需要添加版本参数
--two 使用python2创建虚拟环境
--three 使用python3创建虚拟环境
pipenv install --three
3、虚拟环境创建成功后,需要激活
pipenv shell
#激活环境以后可以使用 python xxx.py 运行脚本
#不激活环境可以使用 pipenv run python xxx.py 运行脚本
激活虚拟环境后,即可以在当前的虚拟环境进行一系列操作
#模块安装 pipenv install aaa
#模块卸载 pipenv uninstall aaa
#查看模块之间的依赖 pipenv graph
#查看虚拟环境的所有模块 pip list
#查看pipenv所处的项目路径 pipenv --where
#查看创建的虚拟环境的路径 pipenv --venv
#退出虚拟环境 exit
#删除虚拟环境 pipenv --rm
4、管理python依赖
#导出虚拟环境所有依赖的包名 pip freeze > requirements.txt
#安装项目所依赖的全部模块 pip install -r requirements.txt