Does it make sense to specify range of allowed Python versions in environment.yml file? I got this idea while reading the Google's Biq Query documentation
Supported Python Versions
Python >= 3.7, < 3.11
If this makes sense then what is the right syntax to specify the range in the environment.yml file?
While there is nothing logically incorrect with specifying a version range for Python, it has the downside of defining a large solution space, which can lead to slow solving. For practical environments, I would recommend specifying the version for python through the minor version, e.g., python=3.9.
Note that this behavior mostly pertains to central packages that define variants of other packages, like python, r-base, or cudatoolkit. For most other packages, the impact is not as drastic.
Here is a simple environment for basic data analysis, with and without the Python version specified.
so-py39.yaml
name: so-py39
channels:
- conda-forge
- nodefaults
dependencies:
- python ==3.9
- ipykernel
- numba
- pandas
- scikit-learn
- scipy
so-py3x.yaml
name: so-py3x
channels:
- conda-forge
- nodefaults
dependencies:
- python >=3.7,<4.0
- ipykernel
- numba
- pandas
- scikit-learn
- scipy
First, we can use the regular conda command.
Command
command time conda env create -dqn foo -f [file]
Timing creating environment: so-py39.yaml
20.51 real 19.57 user 0.94 sys
20.73 real 19.84 user 0.97 sys
19.43 real 18.66 user 0.95 sys
19.22 real 18.36 user 0.92 sys
19.34 real 18.48 user 0.94 sys
19.08 real 18.16 user 0.94 sys
Timing creating environment: so-py3x.yaml
30.53 real 29.56 user 1.00 sys
29.21 real 28.21 user 1.08 sys
31.13 real 29.77 user 1.07 sys
29.93 real 28.46 user 0.99 sys
30.53 real 29.43 user 0.98 sys
28.60 real 27.68 user 1.03 sys
That is, solving for the environment with a range takes ~10s (~50%) longer.
We can also test solving the environment with Mamba.
Command
command time mamba env create -dqn foo -f [file]
Timing creating environment: so-py39.yaml
3.30 real 2.79 user 0.49 sys
3.36 real 2.84 user 0.51 sys
3.25 real 2.74 user 0.49 sys
3.34 real 2.82 user 0.51 sys
3.29 real 2.78 user 0.51 sys
3.24 real 2.74 user 0.48 sys
Timing creating environment: so-py3x.yaml
3.27 real 2.79 user 0.47 sys
3.26 real 2.78 user 0.46 sys
3.33 real 2.83 user 0.48 sys
3.28 real 2.79 user 0.47 sys
3.31 real 2.81 user 0.49 sys
3.29 real 2.81 user 0.47 sys
This indicates that when using Mamba the difference in solve time is neglible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With