conda 和 anaconda 学习笔记
2020-03-13
- 使用 RMarkdown 的
child
参数,进行文档拼接。 - 这样拼接以后的笔记方便复习。
- 相关问题提交到 GitHub
本文主要参考 Mertz (2018) 的网络教程。
1 特性
Conda packages can include data, images, notebooks, or other assets. The command-line tool
conda
is used to install, remove and examine packages; other tools such as the GUI Anaconda Navigator also expose the same capabilities. (Mertz 2018 * What are packages and why are they needed? | Shell)
conda
可以安装数据、图片、Notebook 等,还可以管理 Python 包,和 Anaconda Navigator 功能类似。
conda
安装包时,dependency 包一起自动安装。
2 查看版本
conda -V
conda 4.5.0
conda --version
conda 4.5.0
3 安装包
conda install *
conda install attrs=17.3
这表示安装MAJOR = 17
和 MINOR = 3
的最新 PATCH
的版本
conda install 'bar-lib=1.0|1.4*'
安装bar-lib
包的1.0
版本或者1.4
版本。并且注意'
。
conda install 'bar-lib>=1.3.4,<1.1'
安装bar-lib
包的区间内的版本。
conda install -c conda-forge youtube-dl
youtube-dl
包不再默认路径内,因此要给定-c
4 更新包
conda update foo bar blob
更新多个包
5 删除包
conda remove PKGNAME
6 查询包
conda search attrs
和
conda list attrs
功能类似。
conda search -c conda-forge -c sseefeld -c gbrener --platform win-64 textadapter
- 查找发布者
conda-forge
、sseefeld
、gbrener
的包 -c
表示--channel
--platform win-64
限制了平台,还有osx-64
可以参考
这样可以安装自己需要的包,还能限制版本。
anaconda search boltons
anaconda search *
可以查询包对应的channels和platforms。
7 查询dependency
$ conda info cytoolz=0.8.2=py36_0
cytoolz 0.8.2 py36_0
--------------------
file name : cytoolz-0.8.2-py36_0.tar.bz2
name : cytoolz
version : 0.8.2
build string: py36_0
build number: 0
channel : https://repo.continuum.io/pkgs/free
size : 352 KB
arch : x86_64
constrains : ()
date : 2016-12-23
license : BSD
md5 : cd6068b2389b1596147cc7218f0438fd
platform : darwin
subdir : osx-64
url : https://repo.continuum.io/pkgs/free/osx-64/cytoolz-0.8.2-py36_0.tar.bz2
dependencies:
python 3.6*
toolz >=0.8.0
如果需要使用*
,就需要'
$ conda info 'cytoolz=0.8.2=py36*'
cytoolz 0.8.2 py36_0
--------------------
file name : cytoolz-0.8.2-py36_0.tar.bz2
name : cytoolz
version : 0.8.2
build string: py36_0
build number: 0
channel : https://repo.anaconda.com/pkgs/free/linux-64
size : 1.0 MB
arch : x86_64
constrains : ()
date : 2016-12-23
license : BSD
md5 : 857a2eef4ab39d987e493f5edf2e2163
platform : linux
subdir : linux-64
url : https://repo.anaconda.com/pkgs/free/linux-64/cytoolz-0.8.2-py36_0.tar.bz2
dependencies:
python 3.6*
toolz >=0.8.0
cytoolz 0.8.2 py36h708bfd4_0
----------------------------
file name : cytoolz-0.8.2-py36h708bfd4_0.tar.bz2
name : cytoolz
version : 0.8.2
build string: py36h708bfd4_0
build number: 0
channel : https://repo.anaconda.com/pkgs/main/linux-64
size : 364 KB
arch : None
constrains : ()
license : BSD 3-Clause
md5 : 92977087dc2a463e99a1d993f81f40dd
platform : None
subdir : linux-64
timestamp : 1505740267776
url : https://repo.anaconda.com/pkgs/main/linux-64/cytoolz-0.8.2-py36h708bfd4_0.tar.bz2
dependencies:
libgcc-ng >=7.2.0
python >=3.6,<3.7.0a0
toolz >=0.8.0
8 semantic versioning
MAJOR.MINOR.PATCH
MAJOR
: increased when significant new functionality is introduced (often with corresponding API changes).MINOR
: reflect improvements (e.g., new features) that avoid backward-incompatible API changes.- adding an optional argument to a function API (in a way that allows old code to run unchanged
PATCH
: bug fixes
9 查看所有安装包的版本
conda list
conda list --export > package-list.txt
conda list pandas
$ conda list 'numpy|pandas'
# packages in environment at /home/repl/miniconda:
## Name Version Build Channel
numpy 1.14.0 py36h3dfced4_1
pandas 0.22.0 py36hf484d3e_0
conda list
配合正则化标准可以查询对应的格式
$ conda list -n pd-2015 'pandas|numpy'
$ conda list --name pd-2015 'pandas|numpy'
-n
指定对应的安装环境
10 查询所有安装环境
$ conda env list
# conda environments:
#
course-env /.conda/envs/course-env
pd-2015 /.conda/envs/pd-2015
py1.0 /.conda/envs/py1.0
test-env /.conda/envs/test-env
base /home/repl/miniconda
course-project * /home/repl/miniconda/envs/course-project
*
表示目前的环境
11 安装环境切换
(base) $ conda activate course-env
(course-env) $ conda env list
# conda environments:
#
course-env * /.conda/envs/course-env
pd-2015 /.conda/envs/pd-2015
py1.0 /.conda/envs/py1.0
test-env /.conda/envs/test-env
base /home/repl/miniconda
(course-env) $ conda activate pd-2015
(pd-2015) $ conda deactivate
(base) $
conda activate *
切换环境conda deactivate
切回默认环境
12 删除环境
conda env remove --name ENVNAME
直接用电脑管家, 卸装老版 anaconda 和 R,可以交互更加友好一些。
13 新建环境
conda create --name base2 python=3.6 pandas numpy scipy statsmodels
pip install tensorflow
pip install scikit-learn
pip install Keras
pip install gensim
tensorflow 安装参考 https://www.tensorflow.org/install/pip
也不必须提前声明包,因为可以之后安装的。
这里有两个参考文档可以下载。
这个是根据制定yml
文件进行创建
(base) $ cat shared-config.yml
name: functional-data
channels:
- defaults
dependencies:
- python=3
- cytoolz
- attrs
yml
文件里面有name,因此不需要写。
安装好了,通过以下命令打开 notebook
14 导出环境
(base) $ conda env export -n course-env -f course-env.yml
- 这是一个
yaml
1格式,类似于sessionInfo()
。 -f
等于--file
## name: base
## channels:
## - defaults
## dependencies:
## - appnope=0.1.0=py37_0
## - asn1crypto=0.24.0=py37_0
## - backcall=0.1.0=py37_0
## - blas=1.0=mkl
## - bleach=3.1.0=py37_0
## - ca-certificates=2019.1.23=0
## - cairo=1.14.12=hc4e6be7_4
## - certifi=2019.3.9=py37_0
## - cffi=1.11.5=py37h6174b99_1
## - chardet=3.0.4=py37_1
## - conda=4.6.14=py37_0
## - conda-env=2.6.0=1
## - cryptography=2.4.2=py37ha12b0ac_0
## - cycler=0.10.0=py37_0
## - dbus=1.13.6=h90a0687_0
## - decorator=4.3.2=py37_0
## - entrypoints=0.3=py37_0
## - expat=2.2.6=h0a44026_0
## - fontconfig=2.13.0=h5d5b041_1
## - freetype=2.9.1=hb4e5f40_0
## - fribidi=1.0.5=h1de35cc_0
## - gettext=0.19.8.1=h15daf44_3
## - glib=2.56.2=hd9629dc_0
## - graphite2=1.3.13=h2098e52_0
## - graphviz=2.40.1=hefbbd9a_2
## - harfbuzz=1.8.8=hb8d4a28_0
## - icu=58.2=h4b95b61_1
## - idna=2.8=py37_0
## - intel-openmp=2019.1=144
## - ipykernel=5.1.0=py37h39e3cac_0
## - ipython=7.2.0=py37h39e3cac_0
## - ipython_genutils=0.2.0=py37_0
## - ipywidgets=7.4.2=py37_0
## - jedi=0.13.2=py37_0
## - jinja2=2.10=py37_0
## - joblib=0.13.2=py37_0
## - jpeg=9b=he5867d9_2
## - jsonschema=2.6.0=py37_0
## - jupyter=1.0.0=py37_7
## - jupyter_client=5.2.4=py37_0
## - jupyter_console=6.0.0=py37_0
## - jupyter_core=4.4.0=py37_0
## - kiwisolver=1.1.0=py37h0a44026_0
## - libcxx=4.0.1=hcfea43d_1
## - libcxxabi=4.0.1=hcfea43d_1
## - libedit=3.1.20170329=hb402a30_2
## - libffi=3.2.1=h475c297_4
## - libgfortran=3.0.1=h93005f0_2
## - libiconv=1.15=hdd342a3_7
## - libpng=1.6.36=ha441bb4_0
## - libsodium=1.0.16=h3efe00b_0
## - libtiff=4.0.10=hcb84e12_2
## - libxml2=2.9.9=hab757c2_0
## - llvm-openmp=4.0.1=hcfea43d_1
## - markupsafe=1.1.0=py37h1de35cc_0
## - matplotlib=3.0.3=py37h54f8f79_0
## - mistune=0.8.4=py37h1de35cc_0
## - mkl=2019.3=199
## - mkl_fft=1.0.10=py37h5e564d8_0
## - mkl_random=1.0.2=py37h27c97d8_0
## - nbconvert=5.3.1=py37_0
## - nbformat=4.4.0=py37_0
## - ncurses=6.1=h0a44026_1
## - notebook=5.7.4=py37_0
## - numpy-base=1.15.4=py37h6575580_0
## - openssl=1.1.1b=h1de35cc_1
## - pandoc=2.2.3.2=0
## - pandocfilters=1.4.2=py37_1
## - pango=1.42.4=h060686c_0
## - parso=0.3.2=py37_0
## - pcre=8.42=h378b8a2_0
## - pexpect=4.6.0=py37_0
## - pickleshare=0.7.5=py37_0
## - pip=18.1=py37_0
## - pixman=0.38.0=h1de35cc_0
## - prometheus_client=0.5.0=py37_0
## - prompt_toolkit=2.0.8=py_0
## - ptyprocess=0.6.0=py37_0
## - pycosat=0.6.3=py37h1de35cc_0
## - pycparser=2.19=py37_0
## - pydot=1.4.1=py37_0
## - pygments=2.3.1=py37_0
## - pyopenssl=18.0.0=py37_0
## - pyqt=5.9.2=py37h655552a_2
## - pysocks=1.6.8=py37_0
## - python=3.7.1=haf84260_7
## - python-dateutil=2.7.5=py37_0
## - python.app=2=py37_9
## - pyzmq=17.1.2=py37h0a44026_2
## - qt=5.9.7=h468cd18_1
## - qtconsole=4.4.3=py37_0
## - readline=7.0=h1de35cc_5
## - requests=2.21.0=py37_0
## - ruamel_yaml=0.15.46=py37h1de35cc_0
## - scikit-learn=0.21.1=py37h27c97d8_0
## - scipy=1.2.1=py37h1410ff5_0
## - send2trash=1.5.0=py37_0
## - setuptools=40.6.3=py37_0
## - sip=4.19.8=py37h0a44026_0
## - six=1.12.0=py37_0
## - sqlite=3.26.0=ha441bb4_0
## - terminado=0.8.1=py37_1
## - testpath=0.4.2=py37_0
## - tk=8.6.8=ha441bb4_0
## - tornado=5.1.1=py37h1de35cc_0
## - traitlets=4.3.2=py37_0
## - urllib3=1.24.1=py37_0
## - wcwidth=0.1.7=py37_0
## - webencodings=0.5.1=py37_1
## - wheel=0.32.3=py37_0
## - widgetsnbextension=3.4.2=py37_0
## - xz=5.2.4=h1de35cc_4
## - yaml=0.1.7=hc338f04_2
## - zeromq=4.3.1=h0a44026_3
## - zlib=1.2.11=h1de35cc_3
## - zstd=1.3.7=h5bba6e5_0
## - pip:
## - absl-py==0.7.1
## - astor==0.7.1
## - catboost==0.12.2
## - enum34==1.1.6
## - gast==0.2.2
## - google-pasta==0.1.6
## - grpcio==1.20.1
## - h5py==2.9.0
## - itchat==1.3.10
## - keras-applications==1.0.7
## - keras-preprocessing==1.0.9
## - markdown==3.1
## - mock==3.0.5
## - numpy==1.16.1
## - opencv-python==4.0.0.21
## - pandas==0.24.1
## - pillow==5.4.1
## - protobuf==3.7.1
## - pulp==1.6.9
## - pydot-ng==2.0.0
## - pyparsing==2.3.1
## - pypng==0.0.19
## - pyqrcode==1.2.1
## - python-graphviz==0.10.1
## - pytz==2018.9
## - tb-nightly==1.14.0a20190301
## - tensorboard==1.13.1
## - tensorflow==2.0.0a0
## - tensorflow-estimator==1.13.0
## - termcolor==1.1.0
## - tf-estimator-nightly==1.14.0.dev2019030115
## - werkzeug==0.15.4
## - wxpython==4.0.4
## prefix: /Users/vija/miniconda3
完成
参考
Mertz, David. 2018. “Conda Essentials.” 2018. https://www.datacamp.com/courses/conda-essentials.
YAML (Yet Another Markup Language)↩