0

I'm trying to run a bat file that refers to a python script (runQueries.py) located in the same folder. The bat script looks like this:

python runQueries.py

pause

Error:

Python was not found; run without arguments to install from the Microsoft Store.

My python is saved in User/AppData/Local/Programs/Python

Random Davis
  • 6,662
  • 4
  • 14
  • 24
Irena Rich
  • 160
  • 1
  • 11
  • 3
    How did you install Python? It isn't in your system PATH environment variable, I'd Google how to get it in there, since there's a lot of people who have had similar issues. – Random Davis Jun 04 '21 at 18:13
  • 2
    try `%appdata%\..\local\Programs\Python\python runQueries.py` or add that path directly to your system path varible – user_na Jun 04 '21 at 18:16
  • see also https://superuser.com/questions/143119/how-do-i-add-python-to-the-windows-path – user_na Jun 04 '21 at 18:17
  • 3
    Python does not need to be in your system PATH environment variable, _(or your user PATH environment variable either)_, that's only done as a help to minimize typing for work at the Command prompt, and completely unnecessary in a batch file. `@"%LocalAppData%\Programs\Python\python.exe" "P:\ath\To\runQueries.py" & Pause` seems simple enough to me. – Compo Jun 04 '21 at 18:57

2 Answers2

0

Check your path. Typically, if you've installed Python it would find it early in the path. If you're getting that Microsoft Store message, it wasn't found before it got to the "get it on the Microsoft Store" script.

You may want to explicitly put the absolute path of in the batch file, or make sure your local installation path is early in your path variable.

Ben Y
  • 913
  • 6
  • 18
  • Can you explain that in baby steps for me? Where can I check my path? Should I uninstall and reinstall python to C:? – Irena Rich Jun 04 '21 at 18:14
  • If you open a command prompt, (open this with windows-R and type `cmd` in the resulting box). From the command prompt, type `echo %PATH%` and see what you get. – Ben Y Jun 04 '21 at 18:16
  • This is what I get: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\Irena Rich\AppData\Local\Microsoft\WindowsApps; – Irena Rich Jun 04 '21 at 18:17
  • 1
    This isn't exactly a Python issue, but it's usually how you install Python. I think in your use case, it's probably perfectly fine to specify the entire path to your Python.exe within your batch file. I usually install Python for all users, which tends to have the installer place the installed Python's path early in the PATH variable. YMMV – Ben Y Jun 04 '21 at 18:24
0

I changed my path variable using the instructions here. Thanks to Random Davis for his help.

https://geek-university.com/python/add-python-to-the-windows-path/

Irena Rich
  • 160
  • 1
  • 11
  • Ah, congratulations! Sorry but Windows isn't my environment of choice. – Ben Y Jun 04 '21 at 18:29
  • 1
    As per my comment under your question itself, this was unnecessary. If you have many instances of python to run within your batch file, you can add the location of `python.exe` to the PATH locally for the duration of that batch file, it does not need adding permanently. e.g. `IF "%PATH:~-1%" == ";" (SET "PATH=%PATH%%LocalAppData%\Programs\Python") ELSE SET "PATH=%PATH%;%LocalAppData%\Programs\Python"`. Then use `python.exe` instead of `python`. Alternatively just create your own variable, `SET "PYTH=%LocalAppData%\Programs\Python\python.exe"`, then use `"%PYTH%"` instead of `python`. – Compo Jun 04 '21 at 19:07
  • Thanks for your help, @BenY. It helped point me in the right direction. – Irena Rich Jun 04 '21 at 19:23
  • @Compo love that approach and appreciate the answer. – Irena Rich Jun 04 '21 at 19:24