使用 python虚拟环境和requirements.txt。
This commit is contained in:
parent
bd03c3d651
commit
c857e0df01
21
README.md
21
README.md
|
@ -1,3 +1,24 @@
|
|||
# python_project
|
||||
|
||||
python项目的模板仓库。
|
||||
|
||||
## 1. 使用python虚拟环境
|
||||
### Linux下创建与使用
|
||||
```shell
|
||||
cd $project_root_dir
|
||||
python3 -m venv ./venv
|
||||
. venv/bin/activate # 激活/切换 python环境。同步的,会修改import sys; sys.prefix等变量值
|
||||
|
||||
pip install -r requirements.txt # (不要使用sudo pip,它会使用非虚拟环境)安装在$dir/venv/lib/python3.7/site-packages/
|
||||
|
||||
deactivate # 退出 python虚拟环境
|
||||
rm -rf $project_root_dir/venv/ # 删除虚拟环境, 直接删除文件夹即可
|
||||
```
|
||||
### Windows下
|
||||
> 建议使用pycharm
|
||||
|
||||
## 2. 项目依赖管理
|
||||
- 使用前先查看pip的版本, 区分属于python2或python3:`pip --version`
|
||||
- 记录package依赖:`pip freeze > requirements.txt`
|
||||
- 安装package依赖:`pip install -r requirements.txt`
|
||||
|
||||
|
|
Loading…
Reference in New Issue