I am trying to pip install a .whl file dynamically (the name of the file will change each time I run it) and import it from the same python script. I tried running it in a different subprocess but I am not able to access the import from within the same file. I think python's importlib might have the answer but I haven't been able to figure it out.
import subprocess
import sys
@staticmethod
def install_file(lib):
subprocess.check_call([sys.executable, "-m", "pip3", "install", lib])
# pip install the whl
install_file(whl_file_name)
# dynamically get the name of the .whl file and import it
whl = __import__(whl_file_name)
whl.do_something()
returns the following error
Traceback (most recent call last):
File "<stdin>", line 12, in <module>
ModuleNotFoundError: No module named 'name_of_whl_file'