FAQ
Frequently Asked Questions
Managing Virtual Environments with Conda
Question: Is it possible (or recommended) to create a virtual environment in a specific project folder? Are there advantages or disadvantages to keeping the virtual environment in the default location versus a network drive (e.g., H drive)?
Answer: It is definitely possible to create an environment in a specific project folder/on the H drive (conda create --prefix /path/to/your/project_folder/env_name
)! Note that, to activate the environment, you need to activate it by the full path, not by a name–e.g., conda activate /path/to/your/project_folder/env_name
.
Advantages:
- Backup and Portability: Keeping the environment with the project makes it easier to back up as a single unit and enables access on multiple devices without recreating the environment each time.
Disadvantages:
- Performance: Access speed may be slower on a network drive, and network or permissions issues could make the environment temporarily inaccessible. If you typically work off a network drive, storing your environments within the project folder can be beneficial for organization and consistency.
You need to activate the conda environment stored outside of the default location by the path, not by a name.
conda activate /path/to/your/project_folder/env_name
You may also create a symbolic link in the default envs
folder to point to your custom environment location.
On macOS:
ln -s /path/to/your/project_folder/env_name /path/to/conda/envs/<custom_env_name>
On Windows:
mklink /J "C:\path\to\conda\envs\<custom_env_name>" "H:\path\to\your\project_folder\env_name"
Now, you will be able to activate the environment by name only.
conda activate <custom_env_name>
Question: Will creating a virtual environment for each project lead to memory or storage issues? What is the best practice for closing out a project environment?
Answer: In general, having a virtual environment for each active project shouldn’t cause memory issues. However, it’s good practice to clean up environments when a project concludes.
Here’s a recommended process:
Activating the environment you want to export.
Exporting the environment to a .yaml file with
conda env export > environment.yaml
.After the .yaml file is created (make sure to check before deleting the environment!), you can delete the environment with
conda env remove --name env_name
(orconda env remove --prefix path/to/env_name
if using a specific path).
Tip: By exporting the environment before deletion, you can always recreate the environment later if needed by using:
conda env create --prefix /path/to/your/project_folder/env_name -f environment.yaml
conda activate /path/to/your/project_folder/env_name