Reputation: 41
I have Python 3.7 on my path (I can execute .py
scripts when I am in that local directory in cmd
)
I also have a folder of scripts on my path (I can open them from any local directory in cmd
i.e. by typing "script.py")
However, I cannot execute these scripts from any local directory explicitly using python
, i.e. "python script.py"
Any ideas why this is the case? Thanks
Edit: The desired folder "scripts" is set in PYTHONPATH variable, and checking within python I see
import sys
sys.path
['', 'C:\Users\benma\Desktop\scripts',...
I can import a file from scripts into python already running, but not execute it directly
Upvotes: 2
Views: 1659
Reputation: 8813
Python doesn't search PATH
to look for your scripts. You can run the script directly because the shell is searching PATH
looking for something that matches.
PYTHONPATH
won't help when executing from the shell. It is only used by Python when importing modules:
Augment the default search path for module files.
I don't think you're going to get exactly what you're after. The closest is probably executable modules.
Upvotes: 3