虚拟环境管理pipenv

安装

1
pip install pipenv

基本用法

创建虚拟环境

1
2
3
mkdir demo
cd demo
pipenv install

创建虚拟环境的命令执行之后会在当前目录自动生成Pipfile和Pipfile.lock两个文件,他们主要是用来管理包的。前者负责保存库的信息和python版本的信息,后者负责保存库的哈希值。

进入虚拟环境

1
pipenv shell

在虚拟环境安装一个库

用pipenv安装requests库试一下。

1
pipenv install requests

来看下Pipfile中的内容。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Pipfile

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
requests = "*"

[dev-packages]

[requires]
python_version = "3.7"

看下Pipfile.lock中的内容。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Pipfile.lock

{
"_meta": {
"hash": {
"sha256": "bb57e0...."
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.7"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"certifi": {
"hashes": [
"sha256:2bbf76f...",
"sha256:50b1e4..."
],
"version": "==2021.5.30"
},
"charset-normalizer": {
"hashes": [
"sha256:88fce3f...",
"sha256:c46c3ac..."
],
"markers": "python_version >= '3'",
"version": "==2.0.3"
},
"idna": {
"hashes": [
"sha256:1447504...",
"sha256:467fbad..."
],
"markers": "python_version >= '3'",
"version": "==3.2"
},
"requests": {
"hashes": [
"sha256:6c12465...",
"sha256:b8aa58f..."
],
"index": "pypi",
"version": "==2.26.0"
},
"urllib3": {
"hashes": [
"sha256:39fb867...",
"sha256:f57b4c1..."
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'",
"version": "==1.26.6"
}
},
"develop": {}
}

删除库

1
2
3
4
5
# 删除指定库
pipenv uninstall xxx

# 删除所有库
pipenv uninstall --all

升级库

1
pipenv update

查看库的具体信息

1
pipenv open xxx

检查库的依赖关系

1
pipenv graph

检查库的安全性

1
pipenv check

退出虚拟环境

1
exit

删除虚拟环境

1
pipenv --rm
0%