使用Pipenv来创建虚拟环境

一直听说Pipenv大法好比virtualenv好,今天我们来学习下。

安装
1
pip install pipenv -i https://pypi.douban.com/simple
创建

pipenv就是创建一个虚拟环境和项目绑定,这一点相比于virtualenv具有局限性。

如何和项目绑定呢?

一定要在项目目录下面执行绑定操作。

新建项目

1
2
[root@hongshaorou ~]# mkdir fisher 
[root@hongshaorou ~]# cd fisher/

创建虚拟环境

1
2
3
4
5
6
[root@hongshaorou fisher]# pipenv install 
Creating a virtualenv for this project...
Pipfile: /root/fisher/Pipfile
Using /usr/local/bin/python3.7 (3.7.0) to create virtualenv...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

如果你没有安装 直接允许 pipenv shell 会自动创建一个虚拟环境

进入虚拟环境

1
2
3
4
5
[root@hongshaorou fisher]# pipenv shell 
Launching subshell in virtual environment…
. /root/.local/share/virtualenvs/fisher-zACReBI9/bin/activate
[root@hongshaorou fisher]# . /root/.local/share/virtualenvs/fisher-zACReBI9/bin/activate
(fisher-zACReBI9) [root@hongshaorou fisher]#
安装包
1
(fisher-zACReBI9) [root@hongshaorou fisher]# pipenv install flask  -i https://pypi.douban.com/simple
查看安装的包(包括依赖关系
1
2
3
4
5
6
7
(fisher-zACReBI9) [root@hongshaorou fisher]#  pipenv graph 
Flask==1.0.2
- click [required: >=5.1, installed: 6.7]
- itsdangerous [required: >=0.24, installed: 0.24]
- Jinja2 [required: >=2.10, installed: 2.10]
- MarkupSafe [required: >=0.23, installed: 1.0]
- Werkzeug [required: >=0.14, installed: 0.14.1]
退出
1
(fisher-zACReBI9) [root@hongshaorou fisher]# exit

github地址:https://github.com/pypa/pipenv

参考博客地址:

http://www.dongwm.com/archives/%E4%BD%BF%E7%94%A8pipenv%E7%AE%A1%E7%90%86%E4%BD%A0%E7%9A%84%E9%A1%B9%E7%9B%AE/

https://crazygit.wiseturtles.com/2018/01/08/pipenv-tour/

优先看这个:https://segmentfault.com/a/1190000015143431

知识就是财富
如果您觉得文章对您有帮助, 欢迎请我喝杯水!