Creating a virtual environment for your project
When working with Python projects, it's always a good idea to create a virtual environment. This allows you to create an isolated environment, separate from the system version of Python. Any changes you make to this virtual environment only affects the single project, nothing else. In this way, it's a very safe way to test your projects as they can be deleted and rebuilt very easily. View the following article for further details.
This is important if you want to run 'pip'. Normally, pip attempts to install in the server's default Python system folder. This does not work since you do not have access to this folder. When you create a virtual environment, pip installs locally under your user, so you'll be able to install anything you like without error.
pip is not installed by default. It is only available if you've installed a custom version of Python 2. When you install a custom version, pip is installed with it.
You can then use pip to create a virtualenv, activate it, then run pip to install modules.
After you install a custom version of Python, you should then create a virtualenv that uses this custom version. Once that's created and activated, you can use pip.
To upgrade the version of pip, you must be using a virtualenv. If you do not create a virtualenv using a custom version of Python 2, pip will use the system version. This will fail to upgrade pip or install packages since you do not have access to certain directories on the server.
If you create a virtualenv, you have full access to upgrade and install anything you like.
It's also a good idea to upgrade pip at this point. View the following article for instructions on how to upgrade pip within your virtualenv:
Installing custom modules
It’s recommended that you use pip (in your virtual environment) to easily install custom modules. For example:
(my_project) [server]$ pip install <module>
For example, (e.g., mysqlclient if you're going to use a MySQL database) for your website using pip:
(my_project) [server]$ pip install mysqlclient
View the following links for further details:
After you've created and activated your virtualenv, you may see the following error when installing packages with pip.
SNIMissingWarning: An HTTPS request has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform.
This usually means you're using a Python version older than 2.7.9. To fix this, install these three Python packages to update older libraries.
(my_project) [server]$ pip install pyOpenSSL ndg-httpsclient pyasn1
You should no longer see those errors when installing.
Please note that due to a Linux Kernel upgrade, installing a version of Python lower than 2.7.15 will fail on all DreamHost servers. If you need to install a custom version of Python, make sure it's newer than version 2.7.15.
If you're using Python 3
If you're using Python 3, use the 'pip3' command instead. For example:
(my_project) [server]$ pip3 install mysqlclient
However you would have already had to install a custom version Python3 in a virtualenv:
View the following article for further details: