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/binInstalling Python 3 using
sudo apt-get install python3won’t work as Amazon Linux AMI does not support
apt-getUse instead
yumFirstly, see what installation packages are available that could be a potential match
sudo yum list | grep python3Then install the package wanted
sudo yum install python34which places the files in
/usr/binso no need to change
$PATHNow 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.
pipreturns a concise overview of how the package works. This default installation is located in
/usr/binThe pip package can be updated via
sudo pip install --upgrade pipand doing so appears to move the installation to
/usr/local/binas the executable in
/usr/binno longer works.
pip listreturns 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-packageor something similar.
Where do installed packages get saved?
pip --versionreturns
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-packagesTrying
pip install pyprimesdoes not work and neither does
sudo pip install pyprimesThe former is due to a permission error, the latter as the super user has a different path variable to
$PATHand thus cannot resolve the command
pipTo 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 pyprimesTo complete the verification,
pip show pyprimesreturns
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 pyprimesIn Part 2, we’ll take a look at the virtualenv package.