When distributing Python scripts to non-programmers, you may want to check if dependent modules are installed.
You can use the pip
module to get a list of installed modules and versions.
Although not recommended, you can also install the module from a script.
# coding: utf-8
import pip
#Returns the installed package
pip.get_installed_distributions()
"""
[
'watchdog 0.8.3'
'toml 0.9.1'
'sympy 1.0'
'Sphinx 1.5.2'
'sphinx-rtd-theme 0.1.9'
.
.
.
]
"""
#Package from the script_install name
if pip.main(['install', package_name]) == 0:
print("ok")
If the non-programmer at the distribution destination has the knowledge to launch a black screen (console screen).
From a working PC environment
$ pip freeze > requirements.txt
Distribute the file output in
$ pip install -r requirements.txt --upgrade
It is best to have them do or run the batch file.
Recommended Posts