이 블로그 검색

2017년 12월 5일 화요일

Python 2.7 과 Python 3.5 동시 사용 - Ubuntu

Anaconda2 로 python 2.7 이 설치된 환경에서 root 에 영향이 없이, 다시말해 Anaconda3 를 설치하지 않아도 python 3.5 를 사용하기 위해 다음과 같이 수행

현재 설치된 anaconda2 확인
u0018670@sys-90257:~$ which python
/home/u0018670/anaconda2/bin/python

jupyter kernal 확인
u0018670@sys-90257:~$ jupyter kernelspec list
Available kernels:
  python2    /home/u0018670/anaconda2/share/jupyter/kernels/python2

jupyter notebook 을 실행해봐도 Python2 만 확인

u0018670@sys-90257:~$ conda update conda
Fetching package metadata ...........
Solving package specifications: .

# All requested packages already installed.
# packages in environment at /home/u0018670/anaconda2:
#
conda                     4.3.27                   py27_0

python 3.5 환경으로 업데이트
u0018670@sys-90257:~$ conda create -n py35 python=3.5 anaconda
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment /home/u0018670/anaconda2/envs/py35:

The following NEW packages will be INSTALLED:

    alabaster:                0.7.10-py35_0

    anaconda:                 5.0.0-py35h419c926_0
    anaconda-client:          1.6.3-py35_0
    anaconda-project:         0.6.0-py35_0
    asn1crypto:               0.22.0-py35_0
    astroid:                  1.5.3-py35_0
    astropy:                  2.0.1-np113py35_1
    babel:                    2.5.0-py35_0
    backports:                1.0-py35_0
    beautifulsoup4:           4.6.0-py35_0
    bitarray:                 0.8.1-py35_0
......................
Proceed ([y]/n)? y

python-3.5.4-0 100% |#####################################################################################| Time: 0:00:01  14.46 MB/s
alabaster-0.7. 100% |#####################################################################################| Time: 0:00:00  15.39 MB/s
asn1crypto-0.2 100% |#####################################################################################| Time: 0:00:00  16.71 MB/s
backports-1.0- 100% |#####################################################################################| Time: 0:00:00   3.98 MB/s
beautifulsoup4 100% |#####################################################################################| Time: 0:00:00  18.22 MB/s
bitarray-0.8.1 100% |#####################################################################################| Time: 0:00:00  25.68 MB/s
boto-2.48.0-py 100% |#####################################################################################| Time: 0:00:00   3.83 MB/s
......................
anaconda-5.0.0 100% |#####################################################################################| Time: 0:00:00  12.86 MB/s
#
# To activate this environment, use:
# > source activate py35
#
# To deactivate an active environment, use:
# > source deactivate
#
u0018670@sys-90257:~$ source activate py35
(py35) u0018670@sys-90257:~$ jupyter notebook

(py35) u0018670@sys-90257:~/anaconda2$ which python
/home/u0018670/anaconda2/envs/py35/bin/python

(py35) u0018670@sys-90257:~/anaconda2$ source deactivate
u0018670@sys-90257:~/anaconda2$ 


추가적으로, 특정 버전의 python 패키지를 설치할때는 다음과 같이
그냥 keras 설치를 해버리면 최신 버전이 설치됨.
nimbix@JARVICENAE-0A0A183D:~$ pip install keras
Collecting keras
  Downloading Keras-2.1.2-py2.py3-none-any.whl (304kB)
    100% |████████████████████████████████| 307kB 4.3MB/s
Requirement already satisfied: scipy>=0.14 in ./anaconda3/lib/python3.6/site-packages (from keras)
Requirement already satisfied: six>=1.9.0 in ./anaconda3/lib/python3.6/site-packages (from keras)
Requirement already satisfied: pyyaml in ./anaconda3/lib/python3.6/site-packages (from keras)
Requirement already satisfied: numpy>=1.9.1 in ./anaconda3/lib/python3.6/site-packages (from keras)
Installing collected packages: keras
Successfully installed keras-2.1.2
 

그런데, 
nimbix@JARVICENAE-0A0A183D:~$ pip install keras==1.2
Collecting keras==1.2
  Downloading Keras-1.2.0.tar.gz (167kB)
    100% |████████████████████████████████| 174kB 6.4MB/s
Collecting theano (from keras==1.2)
  Downloading Theano-1.0.1.tar.gz (2.8MB)
    100% |████████████████████████████████| 2.8MB 506kB/s
Requirement already satisfied: pyyaml in ./anaconda3/lib/python3.6/site-packages (from keras==1.2)
Requirement already satisfied: six in ./anaconda3/lib/python3.6/site-packages (from keras==1.2)
Requirement already satisfied: numpy>=1.9.1 in ./anaconda3/lib/python3.6/site-packages (from theano->keras==1.2)
Requirement already satisfied: scipy>=0.14 in ./anaconda3/lib/python3.6/site-packages (from theano->keras==1.2)
Building wheels for collected packages: keras, theano
  Running setup.py bdist_wheel for keras ... done
  Stored in directory: /home/nimbix/.cache/pip/wheels/f8/2c/8e/27d952128220b1acf6fcd5e692269c6e8d60744c15fd160c2c
  Running setup.py bdist_wheel for theano ... done
  Stored in directory: /home/nimbix/.cache/pip/wheels/46/a2/7d/b4cac381d5151daa9f9e0b3e4e4b65edaea6355ae296c97cf2
Successfully built keras theano
Installing collected packages: theano, keras
  Found existing installation: Keras 2.1.2
    Uninstalling Keras-2.1.2:
      Successfully uninstalled Keras-2.1.2
Successfully installed keras-1.2.0 theano-1.0.1
 

기존 2.1.2 를 자동으로 삭제하고 1.2 가 설치됨. 

댓글 없음:

댓글 쓰기