What are good strategies to take a requirements.txt file or take the result of pip freeze
and convert it to a conda environment file? For example, the ideal end result would be to take the requirements.txt with the pinned pip versions and have conda compatible versions under dependencies
rather than under pip
.
name: myconverted_condaenv
channels:
- conda-forge
dependencies:
<all packages installed via pip>
Also, there are some packages that may not be available in conda that were installed via pip. The endgoal of this question is to understand how to help someone quickly convert their setup to use conda without a lot of manual adjustments.
So, it turns out there were already good answers to help me accomplish what I needed. This answer shows how to get the packages without any locked versions.
pip freeze | sed s/=.*// > packages.txt
This answer shows a great loop that will install everything via conda when it can and use pip otherwise.
FOR /F "delims=~" %f in (requirements.txt) DO conda install --yes "%f" || pip install "%f"
Then to generate the actual conda file that can be kept in source control so that new environments can be created from it, you can run
conda env export