Anaconda 虚拟环境的使用

目录

前言

1. 创建虚拟环境

2. 虚拟环境管理

3. Conda虚拟环境的包管理


前言

今天把anaconda进行了滚动更新,实体环境python版本也相应从3.6跟新到了3.7。但是问题来了,之前安装的很多包,如opencv,dlib,等等都找不到对应版本,尴尬.......通常很多东西都是逃避不过去的,迟早会遇到,那么开始对虚拟环境的学习~~~~



1. 创建虚拟环境

conda create -n env_name python=X.X

以下是我的运行过程

# root @ geoffrey-pc in /home/geoffrey [16:02:33]
$ conda create -n Version_36 python=3.6
Solving environment: done ## Package Plan ## environment location: /opt/anaconda/envs/Version_36 added / updated specs:
- python=3.6 The following packages will be downloaded: package | build
---------------------------|-----------------
ncurses-6.1 | hfc679d8_1 1.2 MB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
tk-8.6.8 | ha92aebf_0 3.1 MB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
setuptools-40.4.3 | py36_0 554 KB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
certifi-2018.8.24 | py36_1001 139 KB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
libgcc-ng-7.2.0 | hdf63c60_3 6.1 MB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
xz-5.2.4 | h470a237_1 328 KB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
readline-7.0 | haf1bffa_1 381 KB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
zlib-1.2.11 | h470a237_3 93 KB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
sqlite-3.25.2 | hb1c47c0_0 1.6 MB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
wheel-0.32.1 | py36_0 34 KB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
openssl-1.0.2p | h470a237_0 3.5 MB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
ca-certificates-2018.8.24 | ha4d7672_0 136 KB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
libstdcxx-ng-7.2.0 | hdf63c60_3 2.5 MB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
pip-18.1 | py36_1000 1.8 MB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
libffi-3.2.1 | hfc679d8_5 51 KB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
bzip2-1.0.6 | h470a237_2 310 KB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
python-3.6.6 | h5001a0f_0 20.9 MB https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
------------------------------------------------------------
Total: 42.7 MB The following NEW packages will be INSTALLED: bzip2: 1.0.6-h470a237_2 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
ca-certificates: 2018.8.24-ha4d7672_0 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
certifi: 2018.8.24-py36_1001 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
libffi: 3.2.1-hfc679d8_5 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
libgcc-ng: 7.2.0-hdf63c60_3 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
libstdcxx-ng: 7.2.0-hdf63c60_3 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
ncurses: 6.1-hfc679d8_1 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
openssl: 1.0.2p-h470a237_0 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
pip: 18.1-py36_1000 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
python: 3.6.6-h5001a0f_0 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
readline: 7.0-haf1bffa_1 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
setuptools: 40.4.3-py36_0 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
sqlite: 3.25.2-hb1c47c0_0 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
tk: 8.6.8-ha92aebf_0 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
wheel: 0.32.1-py36_0 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
xz: 5.2.4-h470a237_1 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
zlib: 1.2.11-h470a237_3 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge Proceed ([y]/n)? y Downloading and Extracting Packages
ncurses-6.1 | 1.2 MB | ####################################################### | 100%
tk-8.6.8 | 3.1 MB | ####################################################### | 100%
setuptools-40.4.3 | 554 KB | ####################################################### | 100%
certifi-2018.8.24 | 139 KB | ####################################################### | 100%
libgcc-ng-7.2.0 | 6.1 MB | ####################################################### | 100%
xz-5.2.4 | 328 KB | ####################################################### | 100%
readline-7.0 | 381 KB | ####################################################### | 100%
zlib-1.2.11 | 93 KB | ####################################################### | 100%
sqlite-3.25.2 | 1.6 MB | ####################################################### | 100%
wheel-0.32.1 | 34 KB | ####################################################### | 100%
openssl-1.0.2p | 3.5 MB | ####################################################### | 100%
ca-certificates-2018 | 136 KB | ####################################################### | 100%
libstdcxx-ng-7.2.0 | 2.5 MB | ####################################################### | 100%
pip-18.1 | 1.8 MB | ####################################################### | 100%
libffi-3.2.1 | 51 KB | ####################################################### | 100%
bzip2-1.0.6 | 310 KB | ####################################################### | 100%
python-3.6.6 | 20.9 MB | ####################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > source activate Version_36
#
# To deactivate an active environment, use:
# > source deactivate
#

  

2. 虚拟环境管理

激活环境,不使用实体环境:
 > source activate 虚拟环境名

关闭虚拟环境(即从当前环境退出返回使用PATH环境中的默认python版本):
> source deactivate

删除虚拟环境
> conda remove --name 虚拟环境名 --all

查看当前环境
> conda info -e

3. Conda虚拟环境的包管理

# 查看某个指定环境的已安装包
conda list -n 虚拟环境名

# 安装package,如果不用-n指定环境名称,则被安装在当前活跃环境
conda install -n 虚拟环境名 包名

# 更新package
conda update -n 虚拟环境名 包名

# 删除package
conda remove -n 虚拟环境名 包名

上一篇:Java Thread.join的作用和原理


下一篇:Spark性能优化(基于Spark 1.x)