简体   繁体   中英

Executing Python scripts from windows path variable

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 ie by typing "script.py")

However, I cannot execute these scripts from any local directory explicitly using python , ie "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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM