Skip to content

Instantly share code, notes, and snippets.

@ozika
Last active October 2, 2024 11:02
Show Gist options
  • Select an option

  • Save ozika/97f39e7ae833a1672106f3248972da0b to your computer and use it in GitHub Desktop.

Select an option

Save ozika/97f39e7ae833a1672106f3248972da0b to your computer and use it in GitHub Desktop.
Create virtual env using conda

Set up virtual environment in R and Python

Python

From yml file using conda. Example yml file, create this as my_python_env.yml

name: my_python_env
channels:
  - conda-forge
  - defaults
dependencies:
  - python=3.10
  - jupyterlab==3.2.5
  - matplotlib==3.3.0
  - pandas==1.4.2
  - numpy==1.20.2
  - seaborn==0.11.2

Set up env conda env create -f covid_pyenv.yml

Activate the environment conda activate uncertainty_env

Add to Ipython kernels ipython kernel install --name "covid_pyenv" --user

You can then install packages using pip/conda, to take snapshot of the environment use:
conda env export --no-builds | grep -v "prefix" > my_python_env.yml

More on conda here: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment


R

  1. renv::init()
  2. work install etc
  3. renv::snapshot()
  4. renv::restore() - revert to previous state

Example Rmd script using renv: https://github.com/ozika/trait-anxiety-and-state-inference-zika2022/blob/master/scripts/stats_main.Rmd

@ozika
Copy link
Author

ozika commented Jul 12, 2022

venv

git clone
cd
pip install virtualenv (if you don't already have virtualenv installed)
virtualenv venv to create your new environment (called 'venv' here)
virtualenv venv --python=/usr/bin/python3.7

source venv/bin/activate to enter the virtual environment
pip3 install --upgrade pip

pip install -r requirements.txt to install the requirements in the current environment

@ozika
Copy link
Author

ozika commented Oct 2, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment