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.

2
  • 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. Commented Apr 26, 2022 at 4:18
  • Does this answer your question? Permanently adding a file path to sys.path in Python Commented Apr 27, 2022 at 14:52

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

I was hoping to be able to use explicit invocation without specifying the whole path. But thanks for trying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.