pip和conda

本文最后更新于:5 个月前

pip和conda

参考:搭建人工智能开发环境 第04节_初识conda和pip

https://www.bilibili.com/video/BV1nT4y1d7QU

一、conda

1
2
3
4
5
PS C:\Users\chris> conda
usage: conda-script.py [-h] [-v] [--no-plugins] [-V] COMMAND ...

conda is a tool for managing and deploying applications, environments and packages.

  1. conda info
  2. conda list
  3. conda install
  4. conda uninstall/remove
  5. conda create
  6. conda update/upgrade
  7. conda config
  8. conda search

​ …

1. 清理安装文件

conda clean -p

1
2
3
4
5
6
7
8
9
10
PS C:\Users\chris> conda env list
# conda environments:
#
base * D:\dev\miniconda3
jupyter D:\dev\miniconda3\envs\jupyter

PS C:\Users\chris> conda activate base
(base) PS C:\Users\chris> conda clean -p
There are no unused package(s) to remove.
(base) PS C:\Users\chris>

2. 更新conda

conda update -n base conda

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
PS C:\Users\chris> conda update -n base conda
Channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

environment location: D:\dev\miniconda3

added / updated specs:
- conda


The following packages will be downloaded:

package | build
---------------------------|-----------------
certifi-2024.2.2 | py311haa95532_0 162 KB
conda-24.1.2 | py311haa95532_0 1.2 MB
------------------------------------------------------------
Total: 1.4 MB

The following packages will be UPDATED:

certifi 2023.11.17-py311haa95532_0 --> 2024.2.2-py31
conda 23.11.0-py311haa95532_0 --> 24.1.2-py311h


Proceed ([y]/n)? y


Downloading and Extracting Packages:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
PS C:\Users\chris>

3. 安装模块

conda install numpy

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
PS C:\Users\chris> conda env list
# conda environments:
#
base * D:\dev\miniconda3
jupyter D:\dev\miniconda3\envs\jupyter

PS C:\Users\chris> conda activate base
(base) PS C:\Users\chris> conda install akshare
Retrieving notices: ...working... done
Channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current :

- akshare

Current channels:

- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- defaults

To search for alternate channels that may provide the conda package you're
looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.


PS C:\Users\chris>

4. 管理conda虚拟环境

1
2
3
4
5
6
7
8
# 创建
conda create -n xxx
# 列表
conda env list
# 激活
conda activate xxx
# 退出
conda deactivate
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
PS C:\Users\chris> conda create -n akshare python=3.11
Channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

environment location: D:\dev\miniconda3\envs\akshare

added / updated specs:
- python=3.11


The following packages will be downloaded:

package | build
---------------------------|-----------------
bzip2-1.0.8 | h2bbff1b_5 78 KB
openssl-3.0.13 | h2bbff1b_0 7.4 MB
python-3.11.8 | he1021f5_0 18.3 MB
tzdata-2024a | h04d1e81_0 116 KB
vc-14.2 | h21ff451_1 8 KB
xz-5.4.6 | h8cc25b3_0 587 KB
------------------------------------------------------------
Total: 26.5 MB

The following NEW packages will be INSTALLED:

bzip2 pkgs/main/win-64::bzip2-1.0.8-h2bbff1b_5
ca-certificates pkgs/main/win-64::ca-certificates-2023.12.12-haa95532_0
libffi pkgs/main/win-64::libffi-3.4.4-hd77b12b_0
openssl pkgs/main/win-64::openssl-3.0.13-h2bbff1b_0
pip pkgs/main/win-64::pip-23.3.1-py311haa95532_0
python pkgs/main/win-64::python-3.11.8-he1021f5_0
setuptools pkgs/main/win-64::setuptools-68.2.2-py311haa95532_0
sqlite pkgs/main/win-64::sqlite-3.41.2-h2bbff1b_0
tk pkgs/main/win-64::tk-8.6.12-h2bbff1b_0
tzdata pkgs/main/noarch::tzdata-2024a-h04d1e81_0
vc pkgs/main/win-64::vc-14.2-h21ff451_1
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.27.29016-h5e58377_2
wheel pkgs/main/win-64::wheel-0.41.2-py311haa95532_0
xz pkgs/main/win-64::xz-5.4.6-h8cc25b3_0
zlib pkgs/main/win-64::zlib-1.2.13-h8cc25b3_0


Proceed ([y]/n)? y


Downloading and Extracting Packages:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate akshare
#
# To deactivate an active environment, use
#
# $ conda deactivate

PS C:\Users\chris>
PS C:\Users\chris> conda env list
# conda environments:
#
base * D:\dev\miniconda3
akshare D:\dev\miniconda3\envs\akshare
jupyter D:\dev\miniconda3\envs\jupyter

PS C:\Users\chris> conda activate akshare
(akshare) PS C:\Users\chris> python -V
Python 3.11.8
(akshare) PS C:\Users\chris>
(akshare) PS C:\Users\chris> conda deactivate
PS C:\Users\chris>

5. 查看索引conda虚拟 环境

conda info -e
conda env list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PS C:\Users\chris> conda info -e
# conda environments:
#
base * D:\dev\miniconda3
akshare D:\dev\miniconda3\envs\akshare
jupyter D:\dev\miniconda3\envs\jupyter

PS C:\Users\chris> conda env list
# conda environments:
#
base * D:\dev\miniconda3
akshare D:\dev\miniconda3\envs\akshare
jupyter D:\dev\miniconda3\envs\jupyter

PS C:\Users\chris>

二、pip

1
2
3
4
5
(base) PS C:\Users\chris> pip

Usage:
pip <command> [options]


pip和conda
https://chris-z-su.github.io/2024/03/02/python/pip和conda/
作者
Chris
发布于
2024年3月2日
许可协议