Python comes with a handy-dandy little tool called pip for installing modules that you import in scripts. Python3 comes with a hand-dandy little tool called pip3 for installing modules you import in scripts. A practice I try to follow is to take the version of a module I was using when I wrote a script and create a requirements.txt file alongside it.
Basically, if I import then I’ll add what I imported into the requirements.txt file. This would usually follow the below syntax:
tensorboard==2.0.2tensorflow==2.0.0
tensorflow-estimator-2.0.1
werkzeug-0.16.0
wrapt-1.11.2
Now that I have a requirements file, I can use that to install packages on the next host I run the script on:
pip install -r requirements.txt
But what if I need to make sure that I don’t update beyond those versions. I can use the freeze verb in pip:
pip freeze > requirements.txt
If you end up with a bad install or one that isn’t working properly, you can always uninstall the module.
pip uninstall pandas
You can then install verbosely, using the URI of the project. For example:
pip install -Iv http://www.github.com/krypted/URI-Of-Project
The above will produce verbose logs so that if it’s failing because of a weird reason you can case that down. Do you have other tips or tricks? Drop a comment and I’ll try and add them!
The post Easy Python Module Version Management appeared first on krypted.