Python 3 On Linux Amazon EC2 - Part 1
At the time of writing, the default Python installation on an EC2 instance running Amazon Linux AMI is Python 2.7 and can be found in
/usr/bin
Installing Python 3 using
sudo apt-get install python3
won’t work as Amazon Linux AMI does not support
apt-get
Use instead
yum
Firstly, see what installation packages are available that could be a potential match
sudo yum list | grep python3
Then install the package wanted
sudo yum install python34
which places the files in
/usr/bin
so no need to change
$PATH
Now that we have an up-to-date version of Python, let’s take a look at installing packages. The best way to do so is use a package called pip.
pip
returns a concise overview of how the package works. This default installation is located in
/usr/bin
The pip package can be updated via
sudo pip install --upgrade pip
and doing so appears to move the installation to
/usr/local/bin
as the executable in
/usr/bin
no longer works.
pip list
returns the packages installed by pip. The list shows that there are several pre-installed packages which are in
/usr/lib/python2.7/dist-packages
/usr/lib64/python2.7/dist-package
or something similar.
Where do installed packages get saved?
pip --version
returns
pip 7.1.2 from /usr/local/lib/python2.7/site-packages (python 2.7)
Let’s verify installed packages get saved in
/usr/local/lib/python2.7/site-packages
Trying
pip install pyprimes
does not work and neither does
sudo pip install pyprimes
The former is due to a permission error, the latter as the super user has a different path variable to
$PATH
and thus cannot resolve the command
pip
To get round this, either change the super user path variable or, more simply, specify the full path of the pip executable
sudo `which pip` install pyprimes
To complete the verification,
pip show pyprimes
returns
Metadata-Version: 1.1
Name: pyprimes
Version: 0.1
Summary: Generate and test for prime numbers.
Home-page: http://pypi.python.org/pypi/pyprimes
Author: Steven D'Aprano
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python2.7/site-packages
Requires:
To uninstall,
sudo `which pip` uninstall pyprimes
In Part 2, we’ll take a look at the virtualenv
package.