Skip to content

Instantly share code, notes, and snippets.

@yash-verma1
Created March 2, 2020 23:32
Show Gist options
  • Save yash-verma1/53ed2d45f6e3e31c95eff7eded3ee77c to your computer and use it in GitHub Desktop.
Save yash-verma1/53ed2d45f6e3e31c95eff7eded3ee77c to your computer and use it in GitHub Desktop.
import ruamel.yaml
yaml = ruamel.yaml.YAML()
data = yaml.load(open('anaconda-project.yml'))
requirements = []
for dep in data['dependencies']:
if isinstance(dep, str):
package, package_version, python_version = dep.split('=')
if python_version == '0':
continue
requirements.append(package + '==' + package_version)
elif isinstance(dep, dict):
for preq in dep.get('pip', []):
requirements.append(preq)
with open('requirements.txt', 'w') as fp:
for requirement in requirements:
print(requirement, file=fp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment