用conda 管理python环境
安装conda
通常安装minicoda即可
centos:
略
mac:
brew install miniconda
初始化环境
conda init <shell name>
创建环境2.7环境
conda create -n py27 python=2.7
如果上述安装2.7方式报如下错误,这是因为2.7版本官方已经停止维护了, conda默认channel检索不到python2.7
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
- python=2.7
Current channels:
- https://repo.anaconda.com/pkgs/main/osx-arm64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/osx-arm64
- https://repo.anaconda.com/pkgs/r/noarch
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.
指定渠道方式安装2.7环境
conda create -c 'https://repo.continuum.io/pkgs/free/osx-64' -n py27 python=2.7
进入环境
conda activate py27
退出环境
conda deactivate
常用命令
# 查看环境
conda env --help #查看帮助
conda env list #列出所有的虚拟环境
conda list --name [虚拟环境名] #查看指定虚拟环境下的package
#创建
conda create --name [虚拟环境名] [python的版本] [需要的包]
eg:
conda create --name myenv
conda create --name myenv python=2.7
conda create --name myenv pytohon=2.7 numpy scipy
#克隆
conda create --name [虚拟环境名] -- clone [colne的环境]
eg:
#创建一个和原python环境一样的虚拟环境
conda create --name mybase --clone base
#删除
conda remove --name [虚拟环境名] -all
# 激活取消(默认的环境是base)
activate [虚拟环境名]
deactivate [虚拟环境名]
最后更新于 2022-07-15 14:24:46 并被添加「」标签,已有 6390 位童鞋阅读过。
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处
(base) ➜ Test-Automation activate py2
(base) ➜ Test-Automation activate py2
(base) ➜ Test-Automation conda activate py2
(py2) ➜ Test-Automation python -V
Python 2.7.13 :: Continuum Analytics, Inc.
(py2) ➜ Test-Automation