Silk Web Hosting: Python migration

Modified

With Silk’s migration to a new major OS version, it may be necessary to re-install some Python packages.  Files that were copied to the new Silk hosts may have been compiled with previous OS version dependencies in mind that will not keep working as-is.  The most reliable way to ensure that your Python environment will keep working is to remove and re-install all required packages.

Creating a new Virtual Environment

The best way to isolate installed dependencies for a Python project is with a “Virtual Environment”.  This is a local copy of your installed modules that can be kept separate from other projects and from the rest of the operating system.  Please see Python’s documentation site for more information on Virtual Environments and the built-in venv module.   If you’re already using a virtual environment in your project, you may want to re-create it from scratch.  You can do that like this:  

# 1. Make a backup of your current virtual environment directory
tar -czvf /path/to/project/venv-backup.tar.gz /path/to/project/.venv
 
# 2. Activate your existing virtual environment
source /path/to/project/.venv/bin/activate
 
# 3. Save your current installed packages list to a "requirements" file
pip freeze > /path/to/project/venv_installed.txt
 
# 4. Deactivate your virtual environment
deactivate
 
# 5. Rename or delete your existing virtual environment
mv /path/to/project/.venv /path/to/project/old_venv
# or
rm -rf /path/to/project/.venv
 
# 6. Create a new virtual environment with your preferred
#    Python version and activate it
python3 -m venv /path/to/project/.venv
source /path/to/project/.venv/bin/activate
# A list of available Python versions and their paths
# can be found at https://silk.uvm.edu/manual/python/
 
# 7. Update pip
pip install -U pip
 
# 8. Re-install your requirements
pip install -r /path/to/projects/venv_installed.txt

This process will re-install all of the same packages and versions that you’re currently using.  If something goes wrong during this process, you may need to move to a newer version of one or more of your installed packages.

Non-Virtual Installs

It is also possible to install Python packages to a particular user’s account, rather than using a virtual environment, like this:  

pip install --user <package-name>

For projects using this method, it may still be necessary to reinstall your Python packages.  That can be done like this:  

# 1. Save your current installed packages list to a "requirements" file
pip freeze --user > ~/installed_packages.txt
 
# 2. Re-install your packages
pip install --user --upgrade --force-reinstall -r ~/installed_packages.txt

You can request migration at any time.