Introduce Python 3.5.2 environment on Amazon Linux
Purpose
- Introduce the latest Python 3.5.2 to Amazon Linux so as not to affect the system.
- Compiling depends on the instance specifications, but it takes about 5 minutes.
- (Actually, there is no part specialized for Amazon Linux)
Preparation
- Launch your Amazon Linux instance so that you can ssh login.
procedure
Install required packages
- Install the required packages as it will be built from source.
- If you include sqlite-devel, it will keep the history of ipython.
$ sudo easy_install virtualenv
$ sudo yum groupinstall 'Development tools'
$ sudo yum install openssl-devel
$ sudo yum install sqlite-devel
Install virtualenv
- Install virtualenv, which is used as a mechanism to switch the Python environment.
- This is installed in the Amazon Linux standard Python 2.7.x environment.
$ sudo pip install virtualenv
Build Python 3.5.2.
- Download and compile the source.
- Install in the logged-in user's home directory.
$ mkdir ~/src
$ cd ~/src
$ wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
$ tar zxvf Python-3.5.2.tgz
$ cd Python-3.5.2
$ ./configure --prefix=$HOME/local
$ make
$ make install
Environment switching settings
- Set up a local Python environment. (Only at the beginning)
- The specified directory will be the top directory of the newly set Python environment.
$ virtualenv --python $HOME/local/bin/python3.5 ~/py352
Confirmation of switching
- Switch to Python 3.5.2 by executing the activate script created by virtualenv.
- An environment character is added at the beginning of the prompt.
$ source $HOME/py352/bin/activate
(py352)$ python --version
Python 3.5.2
- To return to the original environment (Python 2.7.x), use the following command.
(py352)$ deactivate
$ python --version
Python 2.7.10
Default to Python 3.5.2.
- Make sure to switch to the Python 3.5.2 environment when logging in.
$ echo 'source $HOME/py352/bin/activate' >> ~/.bash_profile
Set the switching command to alias
- Since the command is troublesome if you go back and forth between the environments frequently, alias is set.
$ echo 'alias p3="source $HOME/py352/bin/activate"' >> ~/.bash_profile