pipenv 是 requests 的作者的另一个神器级别的作品。主要功能是方便的构建Python的虚拟开发环境、进行包的管理。让我们来快速的学习和使用一下吧。
安装
pip install pipenv
创建虚拟环境
输入以下命令
mkdir your_project_name
cd your_project_name
pipenv install
输出内容
Creating a virtualenv for this project…
Pipfile: /Users/hi/Project/eggs/Pipfile
Using /usr/local/opt/python/bin/python3.7 (3.7.3) to create virtualenv…
⠴ Creating virtual environment...Already using interpreter /usr/local/opt/python/bin/python3.7
Using base prefix '/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/hi/.local/share/virtualenvs/eggs-IXiJIWt6/bin/python3.7
Also creating executable in /Users/hi/.local/share/virtualenvs/eggs-IXiJIWt6/bin/python
Installing setuptools, pip, wheel...
done.
✔ Successfully created virtual environment!
Virtualenv location: /Users/hi/.local/share/virtualenvs/eggs-IXiJIWt6
Creating a Pipfile for this project…
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (a65489)!
Installing dependencies from Pipfile.lock (a65489)…
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
进入虚拟环境
pipenv shell
进入虚拟环境中后,就会有以下的输出
➜ eggs pipenv shell
Launching subshell in virtual environment…
. /Users/hi/.local/share/virtualenvs/eggs-IXiJIWt6/bin/activate
➜ eggs . /Users/hi/.local/share/virtualenvs/eggs-IXiJIWt6/bin/activate
(eggs) ➜ eggs
在虚拟环境中安装包
(eggs) ➜ pipenv install django
加快下载速度 🚀
在上一步安装的时候,大家会发现安装的非常慢。这里我们通过替换源的方式,来让下载速度加快。
打开并编辑 Pipfile 将 url = "https://pypi.org/simple"
替换成 url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
随后执行这个命令
pipenv update
后面再安装的速度就非常快啦!