Powershell 下 Conda 安装和配置

Powershell 下 Conda 安装和配置

December 11, 2022
分享 ,

我在考虑要不要把 Nodejs、Python、Ruby 都用 Conda 来管理。
不过先看看相关资料。
已经用上了,真香。

关于 Conda 的发行版本

  • conda 是一个包和环境管理工具,它不仅能管理包,还能隔离和管理不同 python 版本的环境。类似管理 nodejs 环境的 nvm 工具。
  • anaconda 和 miniconda 都是 conda 的一种发行版。只是包含的包不同。
  • anaconda 包含了 conda、python 等 180 多个科学包及其依赖项,体格比较大。但很多东西你未必用到,所以才有 mini 版。
  • miniconda 是最小的 conda 安装环境,只有 conda+python+pip+zlib 和一些其他常用的包,体格非常迷你。
  • pip 也叫包管理器,和 conda 的区别是,pip 只管理 python 的包,而 conda 可以安装所有语言的包。而且 conda 可以管理 python 环境,pip 不行。

安装 Conda

我这里选择安装 miniconda,conda 完全安装似乎要 3 个多 G,没有必要。
我使用的是 Winget 安装(不得不说 Winget 是挺方便的),命令如下:

winget install miniconda3

常用命令

clean        Remove unused packages and caches.
compare      Compare packages between conda environments.
config       Modify configuration values in .condarc. This is modeled after the git config 
                    command. Writes to the   user .condarc file (C:\Users\me\.condarc) by default.
create       Create a new conda environment from a list of specified packages.
help         Displays a list of available conda commands and their help strings.
info         Display information about current conda install.
init         Initialize conda for shell interaction. [Experimental]
install      Installs a list of packages into a specified conda environment.
list         List linked packages in a conda environment.
package      Low-level conda package utility. (EXPERIMENTAL)
remove       Remove a list of packages from a specified conda environment.
uninstall    Alias for conda remove.
run          Run an executable in a conda environment. [Experimental]
search       Search for packages and display associated information. The input is a MatchSpec, 
                   a query language     for conda packages. See examples below.
update       Updates conda packages to the latest compatible version.
upgrade      Alias for conda update.
env list       查看所有环境

等进度条走完就可以用 conda 关键字使用了。

初始化

window 下用 powershell 安装后会出现无法切换 conda 环境的问题,而且不会报错,但是你无法切换环境。我找了很多资料 [1] 后发现要使用 init 命令进行初始化,等执行完后。

conda init powershell

创建虚拟环境

使用 create 命令就可以创建虚拟环境了,-n 设置虚拟环境名称。 后面可以指定安装各种环境包,可以同时安装多个环境。

conda create -n vsdev python=3.8.6 nodejs=18.12.1

激活虚拟环境

使用 activate 激活虚拟环境

conda activate vsdev

管理包

建议统一使用 conda 来管理包,原因可以参见 pip install 和 conda install 的区别

conda install nodejs
conda install pymssql
conda remove nodejs

conda init — conda 22.11.1.post4+22d01b513 documentation ↩︎

加入评论