Pyenv: simple Python version management


To run the commands in this article, you must log into your server via SSH with your Shell user. View the following articles for more information:

pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. Follow the instructions here:

Create a tmp directory

Since the user doesn't have permission to the /var/foo/bar/tmp folder, you will have a "BUILD FAILED" error. Make sure you create a tmp folder in your user's home directory and tell pyenv to use it:

[server]$ cd ~
[server]$ mkdir tmp
[server]$ echo 'export TMPDIR="$HOME/tmp"' >> ~/.bash_profile

Due to resource limitations on shared hosting, your processes may be killed when compiling modules. The best solution is to use 'anaconda' or 'miniconda' packages under 'pyenv'.

Install pyenv

You can find the instructions to install here:

The following steps explain how to install under your DreamHost username.

  1. Make sure you're in your user's home directory.
    [server]$ cd ~
  2. Clone the repository.
    [server]$ git clone ~/.pyenv
  3. Run the following three commands to add lines to your .bash_profile.
    [server]$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
    [server]$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
    [server]$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
  4. Restart your Shell.
    [server]$ exec "$SHELL"
  5. Check what packages are available to install.
    [server]$ pyenv install --list 
  6. Install a package. For example:
    [server]$ pyenv install anaconda-x.x.x

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?