[Python] How to run .py script from anywhere in command line (windows)

Discussão em 'Python' iniciado por Stack, Setembro 6, 2025.

  1. Stack

    Stack Membro Participativo

    I know this has been asked plenty of times but I haven't found a satisfactory answer to my particular question (maybe it's out there but I didn't check every single related thread).

    Simply put, I want to able to run a .py script from anywhere in command line WITHOUT having to go to the folder where it's located. Is this possible? Despite having both python as well as the folder containing my scripts being in the PATH environment variable, I always get the message


    "python: can't open file 'C:\Users\dpodo\Runtime.py': [Errno 2] No such file or directory"
    ​

    From what I've found so far, Windows can't explicitly run python scripts from anywhere, it can only do this with executable files, but I refer to you guys to help me out here.

    As above, already tried adding python and the script folder to PATH, and Googling a bit, as well as checking a few threads here on SO.

    Continue reading...

Compartilhe esta Página