Installing a custom version of Python 3

Python3 is not installed on DreamHost servers but you can install it manually using a Shell user. To install a custom Python version, you must download the version from python.org.

The following describes how to install Python 3.6.2 and 3.7.1 under your website user.

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

Installing Python 3.6.2

  1. Log into your server via SSH, and then run the following commands one at a time:
    [server]$ cd ~
    [server]$ mkdir tmp
    [server]$ cd tmp
    [server]$ wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
    [server]$ tar zxvf Python-3.6.2.tgz 
    [server]$ cd Python-3.6.2
    [server]$ ./configure --prefix=$HOME/opt/python-3.6.2 [server]$ make [server]$ make install
    • These commands install your local version of python to /home/<username>/opt/python-3.6.2.
  2. Navigate back to your user's home directory:
    [server]$ cd ~
  3. View the creating and editing a file via SSH article for instructions on how to edit your existing .bash_profile. To use the new version of Python over the system default, enter the following line to your .bash_profile:
    export PATH=$HOME/opt/python-3.6.2/bin:$PATH
  4. Save and close the file, and then return to your shell. Run the following command to update this file:
    [server]$ . ~/.bash_profile
  5. Check which version of Python you're now using by entering the following command:
    [server]$ which python3
    /home/username/opt/python-3.6.2/bin/python3

    You can also check the version:

    [server]$ python3 --version
    Python 3.6.2

    If there is no response then the newly downloaded copy is not being used. Most often this is due to the .bash_profile not being updated correctly. Try logging out and back in again. If necessary, repeat the steps above.

Installing Python 3.7.1

Important note about version 3.7.1

Version 3.7.1 requires newer versions of OpenSSL (1.0.2 or newer) than what DreamHost's servers currently provide. As such, you'll need to also install OpenSSL locally, then configure Python to use this local version of OpenSSL. View the following link for details:

This states the following:

Changed in version 3.6: OpenSSL 0.9.8, 1.0.0 and 1.0.1 are deprecated and no longer supported. In the future the ssl module will require at least OpenSSL 1.0.2 or 1.1.0

DreamHost's OpenSSL version is currently 1.0.1f. To use newer versions of Python, you'll need to install the required version of OpenSSL locally under your user.

Installing OpenSSL

View the following article for instructions on installing OpenSSL locally under your Shell user:

Installing Python 3.6.2

  1. Log into your server via SSH, and then run the following commands one at a time:
    [server]$ cd ~
    [server]$ mkdir tmp
    [server]$ cd tmp
    [server]$ wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
    [server]$ tar zxvf Python-3.7.1.tgz 
    [server]$ cd Python-3.7.1
  2. Change into the 'Modules' directory.
    [server]$ cd Modules
  3. Edit the file titled 'Setup.dist'. The section you're looking for is around line #211. View the 'Editing a file using vim' article for instructions.
    [server]$ vim +211 Setup.dist
  4. You'll need to edit line #211-214 by removing the # sign in front of those lines. You must also edit the first line to the path where you installed OpenSSL locally under your user. This assumes you followed the article and installed it in a directory named 'openssl'. Make sure to change 'username' to your Shell user.
    SSL=/home/username/openssl
    _ssl _ssl.c \
            -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
            -L$(SSL)/lib -lssl -lcrypto
  5. Change back to the Python-3.7.1 directory. You can now configure and install Python.
    [server]$ cd ..
    [server]$ ./configure --prefix=$HOME/opt/python-3.7.1
    [server]$ make
    [server]$ make install
    • These commands install your local version of python to /home/<username>/opt/python-3.7.1.
  6. Navigate back to your user's home directory:
    [server]$ cd ~
  7. View the creating and editing a file via SSH article for instructions on how to edit your existing .bash_profile. To use the new version of Python over the system default, enter the following line to your .bash_profile:
    export PATH=$HOME/opt/python-3.7.1/bin:$PATH
  8. Save and close the file, and then return to your shell. Run the following command to update this file:
    [server]$ . ~/.bash_profile
  9. Check which version of Python you're now using by entering the following command:
    [server]$ which python3
    /home/username/opt/python-3.7.1/bin/python3

    You can also check the version:

    [server]$ python3 --version
    Python 3.7.1

    If there is no response then the newly downloaded copy is not being used. Most often this is due to the .bash_profile not being updated correctly. Try logging out and back in again. If necessary, repeat the steps above.

Troubleshooting

It's possible you'll see the following error after installing version 3.7.1 when running pip.

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

This means that the local version of OpenSSL you installed was not configured correctly before you configured Python. View the following article for instructions on how to install OpenSSL locally.

If you're still seeing the error, re-install Python.

If you're using Django

If you're using Django, make sure to view the following articles:

See also

Did this article answer your questions?

Article last updated PST.