前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >(三十四)初遇python之Pipenv(windows)

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

作者头像
XXXX-user
修改2019-07-30 10:40:29
8070
修改2019-07-30 10:40:29
举报
文章被收录于专栏:不仅仅是python不仅仅是python

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

1.什么是Pipenv?

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

2.如何安装Pipenv?

使用pip install pipenv进行安装

3.使用Pipenv ?

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

代码语言:javascript
复制
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)进入虚拟环境

代码语言:javascript
复制
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环境信息

代码语言:javascript
复制
(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环境

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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 查看命令使用帮助

代码语言:javascript
复制
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记公众号

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-06-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 yale记 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 关注公号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档