Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a conda environment from global python environment?

Tags:

python

conda

Say I have a coworker who doesn't use conda, but instead uses a global python environment.

Is there a way for the coworker to use conda to create a conda environment from his global python environment?

The goal is for me to easily create a conda environment on my computer which matches his python environment.

like image 399
user3731622 Avatar asked Jan 26 '23 08:01

user3731622


1 Answers

On his side:

pip freeze > requirements.txt

On your side:

conda env create -n [ENV_NAME] -f requirements.txt


EDIT: This only works when 1) both environments are the latest python version, and 2) every package in the specific version that your coworker has, exists in conda. 1 can be resolved through:

conda create -n [ENV_NAME] python=[PYTHON_VER] -f requirements.txt

There isn't a one-step way to do 2 in conda afaik, what I would do is to (as stated in Lokinou's answer) first create a conda env in the desired python version, then install via pip:

conda create -n [ENV_NAME] python=[PYTHON_VER]
conda activate [ENV_NAME]
pip install -r requirements.txt
like image 143
Melvin Avatar answered Jan 30 '23 01:01

Melvin