2

I have a problem with a batch file I use to deploy software on new computers.
For example, I install Python 2.7, and next I would like to upload pip to install all libraries. My batch return the error could not update pip , python is not recognize as internal command or batch. I have to close the script and reopen it.

Is there a way to refresh my cmd environment without closing it ?

I am not English so I hope you will understand me.

I am under Windows 7 PRO 64 bits and I use cmd.exe.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Pixi
  • 33
  • 1
  • 7
  • 1
    If you know the location where Python was installed, you could add it to the current `PATH` variable and keep going. – lit Dec 05 '18 at 13:55
  • Due to legacy weirdness, the standard install puts python.exe in the base installation directory and scripts and other executables in the "Scripts" subdirectory. So you'll need to add both directories to `PATH`, e.g. `set "PATH=%PATH%;Path\To\Python;Path\To\Python\Scripts"`. Note that the quotes go around the entire assignment expression, *not* individual path components. – Eryk Sun Dec 05 '18 at 18:00
  • Use the code I posted in my answer on [IExpress Post Installation Batch with NodeJS not finding NPM immediately](https://stackoverflow.com/a/51897924/3074564) after installation of __Python__ in your batch file to update all local environment variables according to updated system and user environment variables. – Mofi Dec 06 '18 at 07:05
  • @eryksun i already add the path on my script :) This is more a problem of env variables, so i'm gonna take a look at mofi script. Thannks a lot. – Pixi Dec 06 '18 at 09:31
  • @Pixi, the MSI installer for Python 2 has an option to update the system environment variables in the registry, i.e. "add python.exe to Path", which should refresh Explorer's environment and thus all new processes started from Explorer. For child processes of your script, the environment is inherited from your process by default. Just ensure you're updating `os.environ['PATH']` (not `sys.path`) in your script to include both Python's installation directory and the "Scripts" subdirectory, without quotes. – Eryk Sun Dec 06 '18 at 15:05

2 Answers2

1

I had a similar issue I was trying to automate initial installation on win 7. I first updated the environment variable so when ever I log into the system the paths are updated. Then I changed the current path variable in cmd session:

setx /M path "%path%;C:\path\to\your\exe"
set path="%path%;C:\path\to\your\exe"
Sheece Gardazi
  • 480
  • 6
  • 14
-1

You can "resoure" your .bash_profile on Mac or .bashrc on Linux. This action will recognize changes, which is the same as start a new bash, because when a bash is open, what it does first is load the .bashrc or .bash_profile in.

The answer is also stated here: Is there a way to "resource" by bash_profile without restarting terminal?

NLag
  • 75
  • 6