0

So, running in PowerShell I can normally execute scripts by either typing the name of the script (i.e. bob.py) or by invoking python and the script name (i.e. "python bob.py"), as long as bob.py is on my PATH. Starting today, the second method no longer works. I can still type the name of the script directly (bob.py) but typing "python bob.py" results in a FileNotFound error. Python and bob.py are both on my PATH.

My question: why did this start happening? How do I fix it?

Thanks in advance.

  • Did you start using ise? Do you set path in your script? Sometimes opening PowerShell puts you in c:\windows\ system and makes some paths weird. This is more of a windows path thing then a PowerShell thing. Best practices should always type out the whole path to prevent $path variable attacks from adversaries. – Robert Cotterman Apr 26 '22 at 04:18
  • Does this answer your question? [Permanently adding a file path to sys.path in Python](https://stackoverflow.com/questions/12257747/permanently-adding-a-file-path-to-sys-path-in-python) – Faraaz Kurawle Apr 27 '22 at 14:52

1 Answers1

0

You can do the following:

  1. Type the directory path of the python file.
python "C:\Users\test.py"
  1. use cd command to open powershell in that directory.
cd 'folder_path' 
python test.py
Faraaz Kurawle
  • 1,085
  • 6
  • 24