i'm getting started with pipenv, however, I want to reproduce a project of someone else who worked with conda. I have the corresponding environment.yml file at hand and want to load the required packages into a virtual environment using pipenv install. Of course I could do this manually one by one, but I wonder if there is a more sophisticated way of transforming the environment.yml file into either a pipfile or a requirement.txt file, from which pipenv install would also be able to load the packages in an automated fashion. thanks, Olmo
install packages in virtual environment with pipenv from an environment.yml file
4.5k Views Asked by Olmo AtThere are 3 best solutions below

environment.yml
is a file generate by package manager conda
. While, pipenv
is based on package manger pip
.
AFAIK, it's impossible. pip
and conda
are different tools, and
- they use different format in the generated environment file.
- The package formats supported by them are different
- The cloud hosts for the package distribution are different as well.

Make a file with the name requirements.txt which will include all the names of the packages which you want to install such that each package's name is on a single line.
Then run the command below from the location of the requirements.txt file in your local system:
Step 1: Switch to your environment using the command conda activate environmentname (for windows) or source activate environmentname (for Linux/MacOS). Once switched it will show your environment name inside parenthesis before the command.
Step 2:
Switch to the local directory (containing requirements.txt) staying inside your environment and run the following command:
pip install -r requirements.txt
This will help also: https://pipenv.readthedocs.io/en/latest/advanced/
The way i solved this issue, was to rename the "environment.yml" which is generated by the conda package manager into "requirements.txt" and replace "=" by "==" in order to comply with the different syntax in pipenv. Also, the "environment.yml" file specifies the python version used for the project. This line must be deleted, since the python version is defined by the command
pipenv --python x.x
Then I executed
pipenv -r install requirements.txt
by doing so I avoided copy-pasting all the required packages from the environment.yml file into the shell.