+ 1

Can i make my python file run from cmd without giving the path?

Is there a way to save my python file in my cmd such a way that i can run it from anywhere like a command. I mean i will type only myfilename.py without path address and it will run on cmd

22nd May 2019, 3:11 AM
Souvik Mondal
Souvik Mondal - avatar
3 Antworten
+ 3
Not really, unless you set the current directory to the file that has your folder. From there you can just use myfilename.py
22nd May 2019, 3:14 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
In Linux, you can make your file executable and add the directory to your environment variables. I can't tell exactly how to do it from memory, but it works
22nd May 2019, 5:01 AM
Anna
Anna - avatar
0
On Windows you can add the directory to the environment with: setx path "%path%;c:\DirWhereYourFileIs" then you shuld be able to call your file directly from cmd without including its path
22nd May 2019, 5:33 AM
Helio Gomez
Helio Gomez - avatar