I've implemented what Brian suggests in his comment.
This converts the environment.yaml
to requirements.txt
:
import yaml
with open("environment.yaml") as file_handle:
environment_data = yaml.load(file_handle)
with open("requirements.txt", "w") as file_handle:
for dependency in environment_data["dependencies"]:
package_name, package_version = dependency.split("=")
file_handle.write("{} == {}".format(package_name, package_version))
And this installs the dependencies directly with pip
:
import os
import yaml
with open("environment.yaml") as file_handle:
environment_data = yaml.load(file_handle)
for dependency in environment_data["dependencies"]:
package_name, package_version = dependency.split("=")
os.system("pip install {}=={}".format(package_name, package_version))
NOTE: I've omitted error handling and any other variations of package definitions (e.g., specification of a package version greater than or equal to a certain version) to keep it simple.
dependencies
list and then either invoking pip directly using subprocess` or outputting each entry as one line in arequirements.txt
file – Epitasis