Anaconda指的是一个开源的Python发行版本,其包含了conda、Python等180多个科学包及其依赖项。 因为包含了大量的科学包,Anaconda 的下载文件比较大(约 531 MB),如果只需要某些包,或者需要节省带宽或存储空间,也可以使用Miniconda这个较小的发行版(仅包含conda和 Python)。
Conda是一个开源的包、环境管理器,可以用于在同一个机器上安装不同版本的软件包及其依赖,并能够在不同的环境之间切换
Anaconda包括Conda、Python以及一大堆安装好的工具包,比如:numpy、pandas等
Miniconda包括Conda、Python
安装包 :Anaconda3-4.2.0-Windows-x86_64.exe (4.2对应python3.5)
官网:https://www.anaconda.com/download/#windows
所有历史版本 :https://repo.continuum.io/archive/index.html
安装过程略过 一路默认即可 安装的目录结构
其中包含python的解释器
anaconda在3.4.2版本安装过程默认设置环境变量到path上 可以直接在cmd上输入python
C:\Users\Administrator>python
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
由于 python2和python3语法差别有点大 所以我们可以指定不同的目录作为python不同版本环境 不同环境进行切换即可
默认我们打开
默认进入 root环境也就是 你的anaconda的默认目录
(C:\Program Files\Anaconda3) C:\Users\Administrator>
通过命令查看 当前的环境
c:\test_p2>conda info
Current conda install:
platform : win-64
conda version : 4.2.9
conda is private : False
conda-env version : 4.2.9
conda-build version : 2.0.2
python version : 3.5.2.final.0
requests version : 2.11.1
root environment : C:\Program Files\Anaconda3 (writable) 这里就是默认环境位置
default environment : C:\Program Files\Anaconda3
envs directories : C:\Program Files\Anaconda3\envs
package cache : C:\Program Files\Anaconda3\pkgs
channel URLs : https://repo.continuum.io/pkgs/free/win-64/
https://repo.continuum.io/pkgs/free/noarch/
https://repo.continuum.io/pkgs/pro/win-64/
https://repo.continuum.io/pkgs/pro/noarch/
https://repo.continuum.io/pkgs/msys2/win-64/
https://repo.continuum.io/pkgs/msys2/noarch/
config file : None
offline mode : False
conda命令用于管理在虚拟环境下的包 比如使用conda install在某个虚拟环境下 安装包
C:\>conda
command
info Display information about current conda install.
help Displays a list of available conda commands and their help
strings.
list List linked packages in a conda environment.
search Search for packages and display their information. The input
is a Python regular expression. To perform a search with a
search string that starts with a -, separate the search from
the options with --, like 'conda search -- -h'. A * in the
results means that package is installed in the current
environment. A . means that package is not installed but is
cached in the pkgs directory.
create Create a new conda environment from a list of specified
packages.
install Installs a list of packages into a specified conda
environment.
update Updates conda packages to the latest compatible version. This
command accepts a list of package names and updates them to
the latest versions that are compatible with all other
packages in the environment. Conda attempts to install the
newest versions of the requested packages. To accomplish
this, it may update some packages that are already installed,
or install additional packages. To prevent existing packages
from updating, use the --no-update-deps option. This may
force conda to install older versions of the requested
packages, and it does not prevent additional dependency
packages from being installed. If you wish to skip dependency
checking altogether, use the '--force' option. This may
result in an environment with incompatible packages, so this
option must be used with great caution.
upgrade Alias for conda update. See conda update --help.
remove Remove a list of packages from a specified conda environment.
uninstall Alias for conda remove. See conda remove --help.
config Modify configuration values in .condarc. This is modeled
after the git config command. Writes to the user .condarc
file (C:\Users\Administrator\.condarc) by default.
clean Remove unused packages and caches.
package Low-level conda package utility. (EXPERIMENTAL)
创建一个名词为 test的虚拟环境 使用python2 (默认会下载最新版本的2 也就是27)
C:\test_p2>conda create -n test_p2 python=2 当然也可以具体版本 比如是=2.6
Fetching package metadata .........
Solving package specifications: ..........
Package plan for installation in environment C:\Program Files\Anaconda3\envs
The following packages will be downloaded:
package | build
---------------------------|-----------------
vs2008_runtime-9.00.30729.5054| 0 1016 KB
vc-9 | 0 705 B
python-2.7.13 | 1 23.8 MB
certifi-2016.2.28 | py27_0 213 KB
wheel-0.29.0 | py27_0 121 KB
wincertstore-0.2 | py27_0 14 KB
setuptools-36.4.0 | py27_1 525 KB
pip-9.0.1 | py27_1 1.6 MB
------------------------------------------------------------
Total: 27.3 MB
The following NEW packages will be INSTALLED:
certifi: 2016.2.28-py27_0
pip: 9.0.1-py27_1
python: 2.7.13-1
setuptools: 36.4.0-py27_1
vc: 9-0
vs2008_runtime: 9.00.30729.5054-0
wheel: 0.29.0-py27_0
wincertstore: 0.2-py27_0
Proceed ([y]/n)? n
因为要下载python包 所以配置私服(window在%APPDATA%/pip/pip.in 具体参考https://pip.pypa.io/en/stable/user_guide/#configuration)
C:\test_p2>cd %APPDATA%
C:\Users\Administrator\AppData\Roaming>mkdir pip
C:\Users\Administrator\AppData\Roaming>cd pip
C:\Users\Administrator\AppData\Roaming\pip>notepad pip.ini
打开的记事本输入
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
虚拟环境 下载完成一半后面会有注释 教你怎么用
#
# To activate this environment, use:
# > activate test_p2
#
# To deactivate this environment, use:
# > deactivate test_p2
#
# * for power-users using bash, you must source
#
conda命令可以再当前虚拟环境下安装和卸载包 比如
# 安装scipy
conda install scipy
# 查看已经安装的packages
conda list
# 查看某个指定环境的已安装包
conda list -n python34
# 查找package信息
conda search numpy
# 安装package
conda install -n python34 numpy
# 如果不用-n指定环境名称,则被安装在当前活跃环境
# 也可以通过-c指定通过某个channel安装
# 更新package
conda update -n python34 numpy
# 删除package
conda remove -n python34 numpy
# 更新python
conda update python
#显示所有创建的虚拟环境
conda env list
1章节中通过 conda create -n test_p2 python=2 创建了一个2的python环境
接下来从 root环境切换到这个新的test_p2环境
activate test_p2
使用info查看该环境所在的位置
(test_p2) c:\test_p2>conda info
Current conda install:
platform : win-64
conda version : 4.2.9
conda is private : False
conda-env version : 4.2.9
conda-build version : 2.0.2
python version : 3.5.2.final.0
requests version : 2.11.1
root environment : C:\Program Files\Anaconda3 (writable)
default environment : C:\Program Files\Anaconda3\envs\test_p2
envs directories : C:\Program Files\Anaconda3\envs
package cache : C:\Program Files\Anaconda3\pkgs
channel URLs : https://repo.continuum.io/pkgs/free/win-64/
https://repo.continuum.io/pkgs/free/noarch/
https://repo.continuum.io/pkgs/pro/win-64/
https://repo.continuum.io/pkgs/pro/noarch/
https://repo.continuum.io/pkgs/msys2/win-64/
https://repo.continuum.io/pkgs/msys2/noarch/
config file : None
offline mode : False
找到他环境的位置 C:\Program Files\Anaconda3\envs\test_p2 发现所有python的解释器和包都在该目录下
安装一个numpy包
(test_p2) c:\test_p2>conda install numpy
虚拟环境目录 /lib/site-packages就可以找到numpy的包
查看所有的虚拟环境
C:\Users\Administrator>conda env list
# conda environments:
#
test_p2 C:\Program Files\Anaconda3\envs\test_p2
root * C:\Program Files\Anaconda3
C:\Users\Administrator>activate test_p2
(test_p2) C:\Users\Administrator>conda env list
# conda environments:
#
test_p2 * C:\Program Files\Anaconda3\envs\test_p2
root C:\Program Files\Anaconda3
(test_p2) C:\Users\Administrator>deactivate test_p2
*表示默认的激活环境 默认是root 使用 activate 名称 激活, deactivate 名称或者关闭dos 又会默认切换回 root
三。 pycharm切换python环境
安装pycharm 参考(https://blog.csdn.net/liaomin416100569/article/details/74532249)python3语法小结(自动化测试)
pycharm 在创建项目时也会默认创建虚拟环境(使用的是virtualenv) 接下来我们使用conda切换到test_p2环境
新建一个python项目 点击 File - Settting
选择project 项目名称 -Project Interpreter
选择第二项 conda环境
选择conda.exe 选择一个location选择python的版本(比如选择2.7) 会自动创建一个location指定目录的虚拟环境 注意勾上 make avaiable to all project 如果使用一个已经存在的环境 点击Existing Environment 点击右边...按钮
使用命令查看
C:\Users\Administrator>conda env list
# conda environments:
#
test_p2 C:\Program Files\Anaconda3\envs\test_p2
test_p3 C:\Program Files\Anaconda3\envs\test_p3
root * C:\Program Files\Anaconda3
你可以在命令行切换 test_p3 安装包 也可以直接在pycharm中
点击右侧的 + 安装新包 比如numpy