I\'m developing a Python application and in the process of branching off a release. I\'ve got a PyPI server set up on a company server and I\'ve copied a source distribution
You could use pip
to install the package programmatically if the import
fails:
try:
import appdirs
except ImportError:
import pip
pip.main(['install', 'appdirs'])
import appdirs
In some circumstances you may need to use importlib
or __import__
to import the package after pip.main
or referesh the PATH
variable. It could also be worthwhile to include a verification if the user really wants to install that package before installing it.
I used a lot of the examples from "Installing python module within code" and I haven't personally tried used this in setup.py
files but it looks like it could be a solution for your question.