1

I have written a (very simple) little Python script, and I want to be able to distribute it to friends who have no idea what Python is, nor anything about Windows cmd scripts. So, fundamentally I need to install Python on their systems, followed by installing the required libraries for my script, followed by my script (and appropriate start-up links in their desktop).

I have no interest in creating some sophisticated install program. So, I have written a very simple, trivial little cmd script to do the install (and created a self-extracting archive that runs the install script.)

In the archive, I have the internet-accessing install executables for installing Python. The script tests for an existing Python install, and when none is found, it installs Python. this works well.

But, after installing Python, I need to install some required modules/libraries that do not come pre-bundled with Python. It would be nice to be able to use pip3 to install these libraries. Fundamentally, this is what needs to be run:

python-3.8.2-webinstall.exe  PrependPath=1
pip3 install --user requests python-dateutil pychromecast gtts

The problem here is that after the Python web install, the process (console process) running this script does not inherit the new settings (esp. the new path settings) from the web install process, and so the pip3 command fails.

My first attempt to remedy this was to use the console START command to start the pip3 command in a separate process that would have the new settings:

python-3.8.2-webinstall.exe  PrependPath=1
START "PythonRequireds" /I /wait cmd /C "pip3 install --user requests python-dateutil pychromecast gtts"

From the documentation for the START command, I would have expected the /I option would ensure the started process had a new environment including the changes from the just-completed web install. Alas, it was not to be: the pip3 command was still not found.

So, my question: does anyone know how to start a new process from a Windows console script, so that the new process has all the changes to the path just placed in the registry by the install process?

David I. McIntosh
  • 1,724
  • 2
  • 17
  • 42
  • Did you check out the related article https://stackoverflow.com/questions/171588/is-there-a-command-to-refresh-environment-variables-from-the-command-prompt-in-w?rq=1 ? – Antares Apr 28 '20 at 06:28
  • Programs inherit the environment from their parent. Programs can, I have no idea if PIP3 does, change the system environment and send a message telling program to reread it. The only known program to do this is Windows Explorer (although sometime in the past I posted a program that tells you it happened). So your changes are lost. –  Apr 28 '20 at 06:49
  • how about [**not** installing phyton](https://stackoverflow.com/questions/5458048/how-to-make-a-python-script-standalone-executable-to-run-without-any-dependency)? – Stephan Apr 28 '20 at 11:40
  • 1
    @Antares Thanks for this. Charles Grunwald's answer there was exactly what I needed. – David I. McIntosh Apr 28 '20 at 13:59
  • @Stephan A very attractive idea that would provide a superior solution to my "install" setup. Unfortunately, my AV program (Avast), and I understand many others, flag the self-contained executables as having virus content. Very unfortunate. – David I. McIntosh May 02 '20 at 18:40
  • 1
    @Stephan Changed anti-virus software. Avast/AVG flag .exe's generated by pyinstaller as virus, Kaspersky does not. – David I. McIntosh May 04 '20 at 04:13
  • 1
    The new environment changes should not be needed if you look into the registry to [get the install path](http://users.tpg.com.au/mpheath/support/61473551.html). This does not relate to getting a new environment as your question asks so is not a related answer, though you could still reach your goal with running pip in the same code. If you want to copy the linked page, you may do so as a permanent record. – michael_heath May 04 '20 at 05:43
  • @michael_heath Thanks for this! Yes, I understand now why you deleted it. But you've saved me time tracking down the reg entries, so thanks, much appreciated. – David I. McIntosh May 04 '20 at 14:09

0 Answers0