Virtual Environment
Last Updated: April 2025
A virtual environment provides an isolated environment that allows unique dependencies to be maintained separately from other environments. For example, if you have multiple projects that all depend on Python, but each has a different set of dependencies - including different versions of some of the same packages - then having a separate virtual environment for each project would not only make sense, but be required since all these projects could not each have their dependencies met and coexist within the same environment.
There are various tools for creating and managing virtual environments for Python. For the sake of an introduction in the context of Tethys Platform, we will provide specific instructions and context for two: conda and venv.
Create Your Virtual Environment
A virtual environment is essentially a folder that can store all of the unique dependnecies (i.e. distinctly versioned packages) of your environment. With conda
, this folder is managed by conda
itself and should not need to be known or hunted down. With venv
you explicitly choose the location of this folder.
Requires Miniconda or Anaconda
Tip
Windows Users: Use the Anaconda Powershell Prompt application for your command line
conda create -n <name>
Where <name>
can be anything alphanumeric, including hyphens and underscores, but no whitespace. We recommend you choose the name of the project that the environment is for, so in this case you could go with tethys
.
The created environment is stored in a location managed by conda
that you should not need to hunt down.
Requires Python >= 3.3
python -m venv <path>
Where <path>
is the absolute or relative path to a folder that will be created to store your environment. You could use tethys
to create this folder in the directory your command line is currently in (i.e. .\tethys
).
Requires Python >= 3.3
python -m venv <path>
Where <path>
is the absolute or relative path to a folder that will be created to store your environment. You could use tethys
to create this folder in the directory your command line is currently in (i.e. ./tethys
).
Activate Your Virtual Environment
Activating a virtual environment essentially switches the context of your command line to that of the specified environment, meaning that when fetching dependencies it will check for them in the active environment's folder first.
conda activate <name>
Where <name>
is what you chose during Create Your Virtual Environment above (e.g. tethys
).
<path>\Scripts\activate
Where <path>
is what you chose during Create Your Virtual Environment above (e.g. tethys
[i.e. .\tethys
]).
source <path>/bin/activate
Where <path>
is what you chose during Create Your Virtual Environment above (e.g. tethys
[i.e. ./tethys
]).
Warning
If you forget to activate your virtual environment before executing commands that depend upon it, you'll encounter errors such as the following:
> tethys start
'tethys' is not recognized as an internal or external command,
operable program or batch file.
$ tethys start
sh: tethys: command not found
Deactivate Your Virtual Environment
Deactivating a virtual environment essentially switches the context of your command line back to the environment you were in prior (usually the default system environment). This leaves your command line as if you had never activated the virtual environment in the first place.
conda deactivate <name>
Where <name>
is what you chose when Creating a Virtual Environment (e.g. tethys
).
deactivate
deactivate