Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip installing environment.yml as if it's a requirements.txt

I have an environment.yml file, but don't want to use Conda:

name: foo
channels:
  - defaults
dependencies:
  - matplotlib=2.2.2

Is it possible to have pip install the dependencies inside an environment.yml file as if it's a requirements.txt file?

I tried pip install -r environment.yml and it doesn't work with pip==22.1.2.

like image 269
Intrastellar Explorer Avatar asked Nov 25 '25 11:11

Intrastellar Explorer


1 Answers

Based on Beni implementation, I just wanted to adjust the code since it has lots of errors;

import os
import yaml

with open("environment.yaml") as file_handle:
    environment_data = yaml.safe_load(file_handle)

for dependency in environment_data["dependencies"]:
    if isinstance(dependency, dict):
      for lib in dependency['pip']:
        os.system(f"pip install {lib}")
like image 89
Ahmed Avatar answered Nov 28 '25 17:11

Ahmed