专栏首页不仅仅是python(三十四)初遇python之Pipenv(windows)

(三十四)初遇python之Pipenv(windows)

各位读者大大们大家好,今天学习python的pipenv,并记录学习过程欢迎大家一起交流分享。

1.什么是Pipenv?

Pipenv是一个新的包管理器,它将pip和virtualenv结合成一个易于使用的工具。

2.如何安装Pipenv?

使用pip install pipenv进行安装

3.使用Pipenv ?

(1)首先在桌面创建一个文件夹名为my_project,在my_project中打开cmd,这里安装一个requests包为例:

C:\Users\Administrator\Desktop\my_project>pipenv install requests
Creating a virtualenv for this project.
Pipfile: C:\Users\Administrator\Desktop\my_project\Pipfile
Using c:\users\Administrator\appdata\local\programs\python\python37\python.exe (3.7.3) to
create virtualenv.
[  ==] Creating virtual environment...Already using interpreter c:\users\Administrator\app
data\local\programs\python\python37\python.exe
Using base prefix 'c:\\users\\Administrator\\appdata\\local\\programs\\python\\python37'
New python executable in C:\Users\Administrator\.virtualenvs\my_project-YidVHweR\Scripts\p
ython.exe
Installing setuptools, pip, wheel...
done.


Successfully created virtual environment!
Virtualenv location: C:\Users\Administrator\.virtualenvs\my_project-YidVHweR
Creating a Pipfile for this project.
Installing requests.
Adding requests to Pipfile's [packages].
Installation Succeeded
Pipfile.lock not found, creating.
Locking [dev-packages] dependencies.
Locking [packages] dependencies.
Success!
Updated Pipfile.lock (444a6d)!
Installing dependencies from Pipfile.lock (444a6d).
  ================================ 5/5 - 00:00:03
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.


C:\Users\Administrator\Desktop\my_project>

首先为my_project创建一个虚拟环境、生成Pipfile、生成虚拟环境、安装requests包,生成Pipfile.lock等

(2)进入虚拟环境

C:\Users\Administrator\Desktop\my_project>pipenv shell
Launching subshell in virtual environment.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
(my_project-YidVHweR) C:\Users\Administrator\Desktop\my_project>

(3)查看虚拟环境中使用的python环境信息

(my_project-YidVHweR) C:\Users\Administrator\Desktop\my_project>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD6
4)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'C:\\Users\\Administrator\\.virtualenvs\\my_project-YidVHweR\\Scripts\\python.exe'
>>>

可知,python的环境使用的是虚拟中的,使用exit可以退出虚拟环境

(4)直接使用pipenv run python进入python环境

C:\Users\Administrator\Desktop\my_project>pipenv run python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
(5)使用pipenv install -r requirements.txt安装第三方的模块
C:\Users\Administrator\Desktop\my_project>pipenv install -r requirements.txt
Requirements file provided! Importing into Pipfile.
Pipfile.lock (7bcbf7) out of date, updating to (444a6d).
Locking [dev-packages] dependencies.
Locking [packages] dependencies.
[=   ] Locking...
......

(6)查看第三方安装的模块依赖,可导出到requirements.txt

C:\Users\Administrator\Desktop\my_project>pipenv lock -r
-i https://pypi.org/simple
certifi==2019.3.9
chardet==3.0.4
idna==2.8
requests==2.22.0
urllib3==1.25.3

(7)卸载包pipenv uninstall requests

C:\Users\Administrator\Desktop\my_project>pipenv uninstall requests
Uninstalling requests.
Uninstalling requests-2.22.0:
  Successfully uninstalled requests-2.22.0


Removing requests from Pipfile.
Locking [dev-packages] dependencies.
Locking [packages] dependencies.
Updated Pipfile.lock (a65489)!

(8)修改虚拟环境中python版本,重新创建环境:pipenv --python 3.6

(9)删除虚拟环境命令:pipenv --rm

(10)安装虚拟环境:pipenv install

(11)查看虚拟环境信息 pipenv --venv

4.使用pipenv -h 查看命令使用帮助

C:\Users\Administrator\Desktop\my_project>pipenv -h
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.

今天初学python的pipenv学习就到这里!

关注公号

下面的是我的公众号二维码图片,欢迎关注。

yale记公众号

本文分享自微信公众号 - yale记(python_yale_learning),作者:yale记

原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。

原始发表时间:2019-06-10

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • (十七) 初遇python甚是喜爱之pip包管理工具使用

    各位读者大大们大家好,今天学习python的pip包管理工具,并记录学习过程欢迎大家一起交流分享。

    亚乐记
  • (四十四) 初遇python之循环后的else

    各位读者大大们大家好,今天学习for、while语句后的else代码块,并记录学习过程欢迎大家一起交流分享。

    亚乐记
  • Django-12 通过邮件找回密码

    首先修改django_project\django_project\settings.py,添加邮件相关的配置:

    亚乐记
  • 印度议会选举,候选人用 DeepFake 伪造方言视频拉票

    内容概要:在近期举行的印度的德里议会选举中,一位候选人使用 DeepFake 技术,生成其他语言的宣传视频,为自己的团队拉取选票。该方式虽然取得了良好的宣传效果...

    HyperAI超神经
  • 轻松理解Keras回调

    随着计算机处理能力的提高,人工智能模型的训练时间并没有缩短,主要是人们对模型精确度要求越来越高。为了提升模型精度,人们设计出越来越复杂的深度神经网络模型,喂入越...

    云水木石
  • Selenium(Webdriver)的安装

    安装selenium前需要确保python安装成功,并且已经安装了pip。安装 pip 的好处是可以使用 pip 命令方便地安装 Python 第三方库。在通过...

    Altumn
  • 对某台服务器事件日志的分析

    进程有规律,短时间内频繁操作。发生该操作的原因最大可能是有重要的文件将要被修改,360防火墙的策略将其禁止。如此频繁的操作是很可疑的。

    用户2202688
  • 详述 Maven 依赖范围及依赖调节原则

    当在我们 POM 文件中配置 Maven 依赖的时候,常见的格式如下: <project> ... <dependencies> ...

    CG国斌
  • TF2.0初体验-使用TF2.0 + Keras构建简单的神经网络

    首先,我们要在电脑里装一个tf2.0的虚拟环境(我的电脑是mac,windows和linux类似)。这里使用anaconda的命令:

    石晓文
  • Tensorflow框架是如何支持分布式训练的?

    大数据时代的互联网应用产生了大量的数据,这些数据就好比是石油,里面蕴含了大量知识等待被挖掘。深度学习就是挖掘数据中隐藏知识的利器,在许多领域都取得了非常成功的应...

    AI科技大本营

扫码关注云+社区

领取腾讯云代金券