参考:Pipenv
该文档用谷歌翻译,不是很好,建议中英文混合食用。
pipenv将pip和virtualenv合在一起使用。
在安装好python和pip之后,用pip安装pipenv
pip install pipenv
推荐使用pipenv作为python的包管理工具,替代掉pip.
指定python版本
$ pipenv --python 3
使用Python3.6:
$ pipenv --python 3.6
使用Python 2.7.15:
$ pipenv --python 2.7.15
进入python项目
使用
cd myproject
pipenv install requests
# 后续要安装任何Python包都用pipenv安装即可,它会自动帮你更新维护下面要提到的Pipfile,Pipfile.lock
如果本项目之前没有使用过pipenv的话,
会创建文件Pipfile,为该项目创建virtualenv,然后安装requests包
如果本项目已经有Pipfile文件,则更新该文件。
创建过程中,终端打印如下:
Creating a Pipfile for this project...
Creating a virtualenv for this project...
Using base prefix '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6'
New python executable in ~/.local/share/virtualenvs/tmp-agwWamBd/bin/python3.6
Also creating executable in ~/.local/share/virtualenvs/tmp-agwWamBd/bin/python
Installing setuptools, pip, wheel...done.
Virtualenv location: ~/.local/share/virtualenvs/tmp-agwWamBd
Installing requests...
Collecting requests
Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests)
Using cached idna-2.6-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests)
Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
Using cached certifi-2017.7.27.1-py2.py3-none-any.whl
Installing collected packages: idna, urllib3, chardet, certifi, requests
Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22
Adding requests to Pipfile's [packages]...
P.S. You have excellent taste! ✨ 🍰 ✨
cd myproject
pipenv install --python /usr/bin/python
根据当前目录的Pipfile为该项目创建virtualenv。