包管理工具之Pipenv
阿新 • • 發佈:2019-02-16
屬性 cif pda tom 工具 all click markers lean
pipenv 都包含什麽?
pipenv 是 Pipfile 主要倡導者、requests 作者 Kenneth Reitz 寫的一個命令行工具,主要包含了Pipfile、pip、click、requests和virtualenv。Pipfile和pipenv本來都是Kenneth Reitz的個人項目,後來貢獻給了pypa組織。Pipfile是社區擬定的依賴管理文件,用於替代過於簡陋的 requirements.txt 文件。
Pipfile的基本理念是:
Pipfile 文件是 TOML 格式而不是 requirements.txt 這樣的純文本。
一個項目對應一個 Pipfile,支持開發環境與正式環境區分。默認提供 default 和 development 區分。
提供版本鎖支持,存為 Pipfile.lock。
click是Flask作者 Armin Ronacher 寫的命令行庫,現在Flask已經集成了它。
接下來,我們看看怎麽使用它吧
安裝和使用
安裝
pip install pipenv
用法
進入當前項目文件夾目錄:
pipenv --three 會使用當前系統的Python3創建環境 pipenv --python 3.6 指定某一Python版本創建環境 pipenv shell 激活虛擬環境 pipenv --where 顯示目錄信息 /home/jiahuan/pipenvtest pipenv --venv 顯示虛擬環境信息 /home/jiahuan/.local/share/virtualenvs/pipenvtest-9KKRH3OW pipenv --py 顯示Python解釋器信息 /home/jiahuan/.local/share/virtualenvs/pipenvtest-9KKRH3OW/bin/python pipenv install requests 安裝相關模塊並加入到Pipfile pipenv install django==1.11 安裝固定版本模塊並加入到Pipfile pipenv graph 查看目前安裝的庫及其依賴 requests==2.18.4 - certifi [required: >=2017.4.17, installed: 2017.11.5] - chardet [required: <3.1.0,>=3.0.2, installed: 3.0.4] - idna [required: >=2.5,<2.7, installed: 2.6] - urllib3 [required: >=1.21.1,<1.23, installed: 1.22]
pipenv check檢查安全漏洞 - Checking PEP 508 requirements… - Passed! - Checking installed package safety… - All good!
pipenv uninstall --all 卸載全部包並從Pipfile中移除
其他命令
E:\python\機器學習和深度學習\深度學習\自然語言處理\lstm-crf\zh-NER-TF>pipenv --help Usage: pipenv [OPTIONS] COMMAND [ARGS]... Options: --where Output project home information. --venv Output virtualenv information. --py Output Python interpreter information. --envs Output Environment Variable options. --rm Remove the virtualenv. --bare Minimal output. --completion Output completion (to be eval‘d). --man Display manpage. --support Output diagnostic information for use in GitHub issues. --site-packages Enable site-packages for the virtualenv. [env var: PIPENV_SITE_PACKAGES] --python TEXT Specify which version of Python virtualenv should use. --three / --two Use Python 3/2 when creating virtualenv. --clear Clears caches (pipenv, pip, and pip-tools). [env var: PIPENV_CLEAR] -v, --verbose Verbose mode. --pypi-mirror TEXT Specify a PyPI mirror. --version Show the version and exit. -h, --help Show this message and exit. Usage Examples: Create a new project using Python 3.7, specifically: $ pipenv --python 3.7 Remove project virtualenv (inferred from current directory): $ pipenv --rm Install all dependencies for a project (including dev): $ pipenv install --dev Create a lockfile containing pre-releases: $ pipenv lock --pre Show a graph of your installed dependencies: $ pipenv graph Check your installed dependencies for security vulnerabilities: $ pipenv check Install a local setup.py into your virtual environment/Pipfile: $ pipenv install -e . Use a lower-level pip command: $ pipenv run pip freeze Commands: check Checks for security vulnerabilities and against PEP 508 markers provided in Pipfile. clean Uninstalls all packages not specified in Pipfile.lock. graph Displays currently-installed dependency graph information. install Installs provided packages and adds them to Pipfile, or (if no packages are given), installs all packages from Pipfile. lock Generates Pipfile.lock. open View a given module in your editor. run Spawns a command installed into the virtualenv. shell Spawns a shell within the virtualenv. sync Installs all packages specified in Pipfile.lock. uninstall Un-installs a provided package and removes it from Pipfile. update Runs lock, then sync.
註:pipenv install 安裝模塊時有時候會很慢
可以設置國內源:Pipfile文件中[source]下面url屬性,比如修改成:url = "https://pypi.tuna.tsinghua.edu.cn/simple"
國內鏡像源的選擇
阿裏雲:http://mirrors.aliyun.com/pypi/simple/ 豆瓣:http://pypi.douban.com/simple/ 清華大學:https://pypi.tuna.tsinghua.edu.cn/simple/ 中國科學技術大學:https://pypi.mirrors.ustc.edu.cn/simple/
包管理工具之Pipenv