1. 程式人生 > >Anaconda3.6 下分別配置py2.7和py3.5環境

Anaconda3.6 下分別配置py2.7和py3.5環境

下載並安裝Anoconda3.6

  • 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

這樣就搞定。

本文總結一下,權當備忘錄/