Reputation: 21
I am installing a python package from a running Python code using the reliable subprocess.popen()
subprocess.Popen([sys.executable, '-m', 'pip', 'install', <path to package wheel>, '--upgrade'], text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
I am trying to import the module using importlib
. This call fails and requires the server to be restarted to be able to load the newly installed module. Is threre any way to dynamically reload the modules in the thread?
I found a similar question that has failed to elicit any response :( Refresh pip installed packages Appreciate if someone can help or guide.
Upvotes: 1
Views: 1552
Reputation: 21
find_spec
does that job. It looks for the package if it does not find an entry in sys.modules
.
importlib.util.find_spec(module_name, package=None)
Upvotes: 1