user5007670
user5007670

Reputation:

how to automatically install dependent modules used in a python app

I just started learning Python and a bit confused about how packages are distributed and installed. I am aware of helper scripts easy_install and pip which can be used to install the dependent modules,howerver I am not clear how to do with programatically,can someone help me on this?

How to install dependent modules automatically when running python applications? I have a dependency on subprocess32 and other modules,I want to automatically install them if they are not present....

  File "script.py", line 6, in <module>
    import subprocess32 as subprocess
ImportError: No module named subprocess32

I have looked at some posts online below but not clear...really appreciate guidance here

locallyoptimal.com/blog/2014/03/14/executable-python-scripts-via-entry-points/ Python packages installation in Windows

Upvotes: 2

Views: 2740

Answers (1)

Jeff
Jeff

Reputation: 2228

Easiest way to handle module installs within a program is with pip:

import pip
pip.main(["install", "numpy"])

For example will install numpy and its dependencies. You can also specify versions using numpy=xxx, or upgrade by passing "-upgrade" between those two above.

Upvotes: 1

Related Questions