Install Python34 and libraries on Amazon EC2

 Access to EC2

Default username is ec2-user. Check your public-dns of your ec2 and login by
ssh -i path/to/your/key.pem ec2-user@public-dns

If you are in Cygwin terminal and Windows, you have to do a little more at first because of Cygwin7s bug. Try
chgrp Users key.pem
chmod 400 key.pem

Install Python3.4

You have python2 by default, but no python3. You will find Python34, which is easily installed
sudo yum list | grep python3
install it
sudo yum install python34

Virtual Environment

I created myenv in /usr/bin
virtualenv -p python3.4 /usr/bin/myenv
check if it works by
[ec2-usr@ip...]$ source /usr/bin/myenv/bin/activate
then your terminal has (myenv) in the beggining of current path. See which versions your python command runs 
[ec2-usr@ip...]$ python
>>> import sys; sys.version 
, which should run with python 34. Now exit python by
>>> exit()
You can come out of virtual environment by
(myenv)[ec2-usr@ip...]$ deactivate
, but for now keep staying in the environment for further steps.

Install Development Tools

(myenv)[ec2-usr@ip...]$ sudo yum groupinstall "Development Tools"
(myenv)[ec2-usr@ip...]$ sudo yum -y install gcc-c++ python27-devel atlas-sse3-devel lapack-devel
(myenv)[ec2-usr@ip...]$ sudo yum install python3.4-devel
To install lxml
(myenv)[ec2-usr@ip...]$ sudo yum install libxml2-devel libxslt-devel python-devel
Some of them may not needed to install python libraries. I'm not sure.

Install python libraries

upgrade pip
(myenv)[ec2-usr@ip...]$ sudo /usr/bin/myenv/bin/pip3 install --upgrade pip
. Pip and pip3 links the same file (You can check by "which pip" and "which pip3"), but they seem not the same sometimes confusingly.

Install numpy

Even in virtual environment, "sudo pip install numpy" installs not in virtual. I do not know why. Fortunately full path works. Also /path/to/pip3 seems better than /path/to/pip.
(myenv)[ec2-usr@ip-...]$ sudo /usr/bin/myenv/bin/pip3 install numpy
. Take a cup of coffee. I do not know why it requires sudo even it installs in the virtual environment. Then see if you can import numpy in the virtual environment
(myenv)[ec2-usr@ip...]$ python
>>>import numpy
>>>numpy.version

Install scipy
(myenv)[ec2-usr@ip-...]$ sudo /usr/bin/myenv/bin/pip3 install scipy

Install matplotlib
(myenv)[ec2-usr@ip-...]$ sudo yum install libpng-devel
(myenv)[ec2-usr@ip-...]$ sudo /usr/bin/myenv/bin/pip3 install matplotlib

Install lxml

(myenv)[ec2-usr@ip-...]$ sudo yum install libxml2-devel libxslt-devel python34-devel
(myenv)[ec2-usr@ip-...]$ sudo /usr/bin/myenv/bin/pip3 install lxml

You may get  an error while installing lxml:
 {standard input}: Assembler messages:
    {standard input}:519888: Error: no such instruction: `c'
    {standard input}: Error: open CFI at the end of file; missing .cfi_endproc directive
    gcc: internal compiler error: Killed (program cc1)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <http://bugzilla.redhat.com/bugzilla> for instructions.
    Compile failed: command 'gcc' failed with exit status 4
    creating tmp
    cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitVml43f.c -o tmp/xmlXPathInitVml43f.o
    cc tmp/xmlXPathInitVml43f.o -L/usr/lib64 -lxml2 -o a.out
    error: command 'gcc' failed with exit status 4

This is possibly because of the lack of memory. You can add swap file (abbreviated current path to copy easily)
sudo dd if=/dev/zero of=/swapfile bs=1024 count=524288
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Then do again installing lxml as above. You can turn off the swap file.
sudo swapoff /swapfile


Install pandas

(myenv)[ec2-usr@ip-...]$ sudo /usr/bin/myenv/bin/pip3 install pandas

Install scikit-learn

(myenv)[ec2-usr@ip-...]$ sudo /usr/bin/myenv/bin/pip3 install scikit-learn

Install Jupyter

(myenv)[ec2-usr@ip-...]$ sudo /usr/bin/myenv/bin/pip3 install jupyter

Install flask

(myenv)[ec2-usr@ip-...]$ sudo /usr/bin/myenv/bin/pip3 install flask

Install jinja2

(myenv)[ec2-usr@ip-...]$ sudo /usr/bin/myenv/bin/pip3 install jinja2

Bibliography

コメント