CodeAlchemy

Jotting one man's journey through software development, programming, and technology


Project maintained by pablogarciaprado Hosted on GitHub Pages — Theme by mattgraham

◀️ Home

Virtual Environments

A virtual environment is an isolated workspace for a Python (or Conda) project where you can install specific packages and dependencies without affecting other projects or the global environment. In short: they let each project have its own clean, independent setup.

Purpose:

Tools:

Conda Environments

Create an environment

conda create --name myenv
conda create --name myenv python=3.9

Delete an environment

conda env remove -n env_name
conda remove --name <env_name> --all

Show the available environments

conda env list
conda info --envs 

Show dependencies installed in the environment

conda list -n myenv

Activate the environment

conda init # necessary to run it first if it's the first time
conda activate myenv

Deactivate the environment

conda deactivate

Locate base directory

Run the following command to locate the base directory where Conda is installed:

conda info | grep -i 'base environment’

Once you have the base directory, append /etc/profile.d/conda.sh to it.

Install dependencies

pip install sheet-logger
pip install sheet-logger==1.0.7.1
pip show sheet-logger # verify the installation
pip install -r requirements.txt

Create an environment based on a requirements.txt

conda create --name myenv python=3.11
conda activate myenv
pip install -r requirements.txt

Generate a requirements.txt

Run the following command to automatically list all the installed packages (and their versions) into a requirements.txt file:

pip freeze > requirements.txt

This will create a requirements.txt file in your current directory with all the installed packages and their respective versions.