-
Notifications
You must be signed in to change notification settings - Fork 1
Python Tips and Tricks
Bill Hereth edited this page Apr 16, 2024
·
2 revisions
Python software and libraries are constantly upgrading. The combinations of these items that were installed together yesterday, may not install nicely today. Recreating a working modeling environment could take hours. Why recreate a modeling environment entirely from scratch, when you can automatically install it using a “recipe”? Creating an established environment is not only great documentation, but also allows you to quickly reinstall modeling environments.
- Open Anaconda Prompt
- Run the following commands:
conda activate myEnvironment
conda env export > environment.yml
conda env create -n new-env-name -f environment.yml
- Conda will create a new environment, with the new name, same python version, and same libraries
- Use the command line tools or sys library in python to get the version number of the environment you will be copying (e.g. 3.9.19)
- Open Command Prompt
- Change directory to the desired python scripts folder
- Run the following commands:
pip freeze > requirements.txt
- Create or download the new python environment with the desired version number
- Change directory to new python environment
- Run the following commands:
pip install -r requirements.txt
Keep a copy of the environment.yaml or requirements.txt in the modeling repository (Optional) Add the name of the python version to the environment.yaml or requirements.txt file e.g. remm_environment_v3_9_19.yaml