Python Virtual Environment in Sandbox
Python Virtual Environment is a Python tool for project isolation. It enables the installation of any Python module you like independently from other python modules in Sandbox.
Python Virtual Environment is basically a folder within your IVM that contains all necessary components: site-packages, symlinks, and scripts to execute Python programs using those Python interpreter and site packages installed in Python Virtual Environment.
In addition, the virtual environment enables installation directly to your home directory and automatic environment configuration so that your packages are found from that environment.
Tutorial
See an example of how to install python packages to Sandbox from Users' meeting recording (at 23min 23sec).
Python Virtual Environment vs Docker Images
Compared to Docker images Python Virtual Environment use the same system as IVM and images cannot be copied from repositories. With Virtual Environments Sandbox users can install packages through /home/ivm
thus needing no request to the service desk (finngen-servicedesk@helsinki.fi). In addition, Virtual Environments are users' personal environments, unlike Docker images which are shared with all Sandbox users.
Example
In this tutorial we will make a Python Virtual Environment for a package we install to python3 (instead of python2, see installation to python2 here). In our example, we use the yhaplo
package.
Step 1:
In Sandbox open Terminal Emulator and go to your home directory
Step 2:
Make a virtual environment named yhaplo_env
Step 3:
Activate virtual environment
Step 4:
The name of your virtual environment will appear indicating you are inside a virtual environment
Step 5:
Copy dependencies from green bucket. (If the dependencies are not yet in green bucket see instructions How to upload to your own IVM via /finngen/green)
Step 6:
Unzip dependencies
Step 7:
Move to unziped folders and install six and yhaplo to virtual environment. Note that the code must be run in the package's folder where setup.py exists.
Step 8:
Check the yhaplo
will show
Step 9:
Deativate virtual environment
Step 10:
Check yhaplo again just to compare
will show
The input data is now editable in /home/ivm/yhaplo-master/input/
as required by the package.
Last updated