Anaconda3.6 下分别配置py2.7和py3.5环境

下载并安装Anoconda3.6

https://www.anaconda.com/download/#linux

  • terminal 直接 bash Anaconda3-5.2.0-Linux-x86_64.sh 即可
  • 注意过程enter : yes or no

检验安装效果

  • 输入: conda -V
  • 输出:
conda 4.5.4
  • 输入:python
  • 输出:
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

到此,证明anaconda安装好了。如果有问题,百度配置以下即可。

基于 python3.5 创建一个名为py3 的环境

conda create --name py3 python=3.5
  • terminal输出:
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.5.4
  latest version: 4.5.11

Please update conda by running

    $ conda update -n base conda
## Package Plan ##

  environment location: /home/veyron/anaconda3/envs/py3

  added / updated specs: 
    - python=3.5


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    certifi-2018.8.24          |           py35_1         139 KB
    setuptools-40.2.0          |           py35_0         571 KB
    python-3.5.6               |       hc3d631a_0        28.3 MB
    wheel-0.31.1               |           py35_0          63 KB
    pip-10.0.1                 |           py35_0         1.8 MB
    ------------------------------------------------------------
                                           Total:        30.8 MB

The following NEW packages will be INSTALLED:

    ca-certificates: 2018.03.07-0           
    certifi:         2018.8.24-py35_1       
    libedit:         3.1.20170329-h6b74fdf_2
    libffi:          3.2.1-hd88cf55_4       
    libgcc-ng:       8.2.0-hdf63c60_1       
    libstdcxx-ng:    8.2.0-hdf63c60_1       
    ncurses:         6.1-hf484d3e_0         
    openssl:         1.0.2p-h14c3975_0      
    pip:             10.0.1-py35_0          
    python:          3.5.6-hc3d631a_0       
    readline:        7.0-h7b6447c_5         
    setuptools:      40.2.0-py35_0          
    sqlite:          3.24.0-h84994c4_0      
    tk:              8.6.8-hbc83047_0       
    wheel:           0.31.1-py35_0          
    xz:              5.2.4-h14c3975_4       
    zlib:            1.2.11-ha838bed_2      

Proceed ([y]/n)? 

Downloading and Extracting Packages
certifi-2018.8.24    |  139 KB | ####################################### | 100% 
setuptools-40.2.0    |  571 KB | ####################################### | 100% 
python-3.5.6         | 28.3 MB | ####################################### | 100% 
wheel-0.31.1         |   63 KB | ####################################### | 100% 
pip-10.0.1           |  1.8 MB | ####################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > source activate py3
#
# To deactivate an active environment, use:
# > source deactivate
#

基于 python2.7 创建一个名为py2 的环境

conda create --name py2 python=2.7
  • 输出:
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.5.4
  latest version: 4.5.11

Please update conda by running

    $ conda update -n base conda



## Package Plan ##

  environment location: /home/veyron/anaconda3/envs/py2

  added / updated specs: 
    - python=2.7


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    python-2.7.15              |       h1571d57_0        12.1 MB
    wheel-0.31.1               |           py27_0          62 KB
    pip-10.0.1                 |           py27_0         1.7 MB
    setuptools-40.2.0          |           py27_0         585 KB
    certifi-2018.8.24          |           py27_1         139 KB
    ------------------------------------------------------------
                                           Total:        14.6 MB

The following NEW packages will be INSTALLED:

    ca-certificates: 2018.03.07-0           
    certifi:         2018.8.24-py27_1       
    libedit:         3.1.20170329-h6b74fdf_2
    libffi:          3.2.1-hd88cf55_4       
    libgcc-ng:       8.2.0-hdf63c60_1       
    libstdcxx-ng:    8.2.0-hdf63c60_1       
    ncurses:         6.1-hf484d3e_0         
    openssl:         1.0.2p-h14c3975_0      
    pip:             10.0.1-py27_0          
    python:          2.7.15-h1571d57_0      
    readline:        7.0-h7b6447c_5         
    setuptools:      40.2.0-py27_0          
    sqlite:          3.24.0-h84994c4_0      
    tk:              8.6.8-hbc83047_0       
    wheel:           0.31.1-py27_0          
    zlib:            1.2.11-ha838bed_2      

Proceed ([y]/n)? y


Downloading and Extracting Packages
python-2.7.15        | 12.1 MB | ####################################### | 100% 
wheel-0.31.1         |   62 KB | ####################################### | 100% 
pip-10.0.1           |  1.7 MB | ####################################### | 100% 
setuptools-40.2.0    |  585 KB | ####################################### | 100% 
certifi-2018.8.24    |  139 KB | ####################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > source activate py2
#
# To deactivate an active environment, use:
# > source deactivate
#

到这里基本搞定。

  • 切换环境测试:
source activate py2
(py2) veyron@veyron-pc:~$ python
Python 2.7.15 |Anaconda, Inc.| (default, May  1 2018, 23:32:55) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.t
>>> exit()
(py2) veyron@veyron-pc:~$ source deactivate
veyron@veyron-pc:~$ source activate py3
(py3) veyron@veyron-pc:~$ python
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 21:41:56) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(py3) veyron@veyron-pc:~$ source deactivate
veyron@veyron-pc:~$ conda -V
conda 4.5.4
veyron@veyron-pc:~$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

配置 Pycharm

File | Settings | Project: mclearning | Project Interpreter | Show
All… 然后进入 Add Python Interpreter,先选左侧Conda Environment ,然后勾选 Existing environment,选择之前配好的py环境
比如需要配置py2.7就 /home/veyron/anaconda3/envs/py2/bin/python
比如需要配置py2.7就 /home/veyron/anaconda3/envs/py3/bin/python

这样就搞定。

本文总结一下,权当备忘录/

感谢下面这篇参考博文:
https://blog.csdn.net/qq_17534301/article/details/80869998

你可能感兴趣的:(Python)