Uppsala Multidisciplinary Center for Advanced Computational Science

How to install your own Python modules or specific Python version

For detailed documentation of pyenv, see the developers homepage: https://github.com/yyuu/pyenv

Important note!

This guide will take you through the steps of installing your own Python so that you can install whatever modules you want in it. The requires you to stop using the module system for loading specific versions of Python. If you start loading python module you will probably break your own python installation and you will have to log out and then back in again to reset it. If you have any loading of python modules in your .bashrc or .bash_profile, this would be a good time to remove them.

You can check if you have any pyton modules loaded by typing the command

module list

If you have any python modules loaded you can unload them, but it is important that you make sure they are not auto-loaded when you log in. Please email the support or ask a linux savvy person in your corridor if you need help with that.

First time only

If this is the first time you read this guide, you will need to install the program pyenv. This is done by typing the following commands:

1. Download pyenv

git clone git://github.com/yyuu/pyenv.git ~/.pyenv

2. Make pyenv start when you login each time

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

To make sure everything gets loaded correctly, log out and back in to uppmax.

Installing your own Python version

This section will show you how to install your own version of python. First you will have to decide which version of python you want to install. The de facto standard version of python today is 2.7.6 so this guide will show you how to install that version.

1. Get pyenv to install the python version of your liking.

pyenv install 2.7.6


2. Make the version you just installed to the standard version for every time you run python.

pyenv global 2.7.6


Now you should be all set. If you change your mind about which version of Python to use, just redo this section and choose a different version. You can also have multiple versions installed at the same time and just switch between them usuing 'pyenv global' as shown above, if you have a script that requires Python 3.3 or any other version.

Installing python packages

To be able to install your own python packages, you will first have to follow the sections 'First time only' and 'Installing your own Python version' above.

To install packages in your python, use pip

pip install [package name]

Example:

pip install mechanize


If you have the need to use multiple virtual environmets in Python, there is a plugin for pyenv that will take care of that, https://github.com/yyuu/pyenv-virtualenv