Check installed modules from Python scripts

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

Check installed modules from Python scripts
[Python] Check the installed libraries
Run Python scripts synchronously from C #
Run Python Scripts from Cisco Memorandum_EEM
Check cybozu.com's SAML authentication from python (pysaml2)
Python nan check
python grammar check
sql from python
MeCab from Python
Automatically check Python scripts with GitHub + Travis-CI + pycodestyle
Make OpenCV3 available from python3 installed with pyenv
Notes on oct2py calling Octave scripts from Python
Use thingsspeak from python
List of python modules
Easy way to check the source of Python modules
Touch MySQL from Python 3
Use fluentd from python
Access bitcoind from python
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Python from or import
Python packages and modules
Use MySQL from Python
Run python from excel
Install python from source
Execute command from Python
Operate neutron from Python!
Use MySQL from Python
Operate LXC from Python
Manipulate riak from python
Force Python from Fortran
Domain check with Python
Use BigQuery from python.
Install the latest Python from pyenv installed with homebrew
Execute command from python
Quickly profile Python scripts
[Python] Read From Stdin
Check version with python
Use mecab-ipadic-neologd from python
[Python] I installed the game from pip and played it
Flatten using Python yield from
Call CPLEX from Python (DO cplex)
Deep Python learned from DEAP
Post from Python to Slack
[Python] Loading multi-level self-made modules
Grammar features added from Python3.6
Cheating from PHP to Python
Check python coverage with pytest-cov
Dynamically import scripts in Python
Make MeCab available from Python3
Information obtained from tweet_id (Python)
OCR from PDF in Python
Python --Check type of values
Understand Python packages and modules
Run illustrator script from python
Use MySQL from Anaconda (python)
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Study from Python Hour4: Object-oriented ②
Access Oracle DB from Python
Study from Python Hour3: Functions
Start / stop GCE from python