So I've seen a handful of half-solutions to this and the answer either seems incomplete or outdated so I'm trying to nail this down. The end user may not have the required python modules installed (and in some cases those are not available through the package manager menu) so I want to check for and install them when a tool is run to avoid the process of walking them through installing it themselves.
So far I have seen the following methods suggested as working:
pip install module
pip.main(['install', module])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', module])
my pip version is above 10.0 so the last command is the suggested solution I've seen but sys.executable points to arcpro.exe. It seems to want to install but during the process will continually open new instances of ArcPro and the installation errors out if I just close the new instances. What do I need to replace sys.exectuable with to make this function correctly or is there a better way?