首页 技术 正文
技术 2022年11月15日
0 收藏 721 点赞 4,676 浏览 1046 个字

安装虚拟环境

安装python3.6

python -m site --user-base

找到 用户基础目录

指定python版本的方式
pipenv --python 3.8
安装

用户范围内安装

pip3.6 install --user pipenv
检查是否安装
pipenv --version

创建虚拟环境

通过创建虚拟环境你可以有一个干净的python环境,并且每一个项目是独立的。

在当前工程的根目录下,创建虚拟环境。

pipenv install

这会在当前项目下创建一个文件夹,其中包含隔离的python解释器环境

显示激活虚拟环境

pipenv shell

pipenv会激活一个虚拟环境,你会发现命令行提示符前添加了虚拟环境"$"。

不显示激活虚拟环境

可在当前的虚拟环境中执行命令。

pipenv run python hello.py

关于依赖

运行安装命令的时候会在当前的目录下生成Pipfile和Pipfile.lock文件,前者用来记录项目依赖包列表,而后者记录了固定版本的详细依赖包列表,pipenv会在安装/删除/更新依赖包的时候,自动更新这两个文件,省去了手动修改requirements.txt文件。

生成lock文件

pipenv lock

列出当前虚拟环境的依赖包

pipenv graph

pipenv list

删除虚拟环境

pipenv --rm

退出pipenv

输入exit

生产requirements.txt

 pipenv lock -r > requirements.txt

安装requirements.txt

 pipenv install -r requirements.txt

总结

当需要在新的环境运行程序的时候,只需要执行pipenv install命令,就会创建一个新的虚拟环境,然后自动从Pipfile中读取依赖并安装到新创建的虚拟环境中。

安装源修改为国内的

可以设置国内源:Pipfile文件中[source]下面url属性,比如修改成:url = "https://pypi.tuna.tsinghua.edu.cn/simple"

同步更新:
博客园:https://www.cnblogs.com/c-x-a/p/9711571.html
微信公众号:python学习开发
掘金:https://juejin.im/user/5bc59d8bf265da0aef4e3c1d
知乎专栏:https://zhuanlan.zhihu.com/c_1010553103958994944
V2EX:https://www.v2ex.com/t/500115
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844