Run your python script from the cmd with its name

If you want to run a python script just writing its name from the command line, without having to write py script_name.py, you can:

  • create a batch file (.bat) like this

py script_name.py

This worked for me:

  • go in the variable environment setting (type var in the search bar and it will show up)
  • in the global settings
  • choose path,
  • then modify,
  • then add the path to your .bat file (without the .bat file)
  • close everything: done.

Open the cmd, write the name of the .bat file and it will work

write var in the search bar and the enviromental variable settings will show up
then click on enviromental variable
Now you can use the name of the batch file to start it frm everywhere
here is the batch file in the myapp_launcher folder

In the pymemo.bat you can write

python book20.py

so that you can launch that script from everywhere just typing pymemo in the command line (you can obviously change the names of the files to more intuitive ones).


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.