How to Run Python Scripts Automatically From Windows Batch Files!

LeMaster Tech
182 followers
Apr 20, 2025
Windows Batch Files are one of the easiest ways to automate running Python .Py Files as if they were executable .exe files!
Be sure to check out the sponsor of today's video PCBWay for all your Electronics and Prototyping Needs! https://pcbway.com/g/2Zlh7L
Don't forget to comment with any questions, and let me know what we should do on the channel next!
Please consider leaving a like on the video and subscribing to the channel, and if LOVE the content from LeMaster Tech feel free to check out our Patreon at the following link: https://www.patreon.com/LeMasterTech
Check out the beatmaker video I made and showed in this video! https://www.youtube.com/watch?v=PxnksbihWrE
hello and welcome back to the channel
and in today's video I am going to show
you how to open python files from
Windows batch files including making
python programs auto run when you start
up Windows
[Music]
initially so I am super excited to bring
you guys this tutorial this is one of
the most requested videos I've ever done
and the question keeps coming up if I
have a python script and I want to
automatically start up when I start up
Windows and I don't want to turn Python
scripts into executables what is the
best way to do that because python is
not a compiled language it's not a
c-based language rather than turning
your files into executables it's
actually just easiest to call python.exe
and then a specific. py file from within
a Windows batch file so what we're going
to look at today is how to call a python
script from a Windows batch file it
doesn't really matter what python script
you use but for my example I'm going to
use a python uh script that I made
previously on the channel this is a beat
maker which uh is basically an
electronic drum kit where you can make
your own BackBeat and uh it's it's
pretty fun um this was actually a big
video for the channel it got featured on
free code Camp um so this was a really
fun video for me and that's why I chose
this project to use but also because
it's kind of complicated it's like over
200 lines of code it calls external
files um and I want to show you how easy
it is to call this from within a batch
file so what I'm going to do is uh I'm
using an IDE here called jet or uh
pycharm by the company jet brains
doesn't really matter what IDE you
develop your python code in as long as
you have uh python installed and you
have a piy file on your computer then
you can develop in whatever IDE you want
the thing I like about uh py arm is when
you run a file when you run a py file it
gives you this path in the bottom which
shows your file path to run python.exe
and then it shows you the file path to
thep file that you're running this just
copying and pasting it into a batch file
is actually like 70% of the work
required so that's what I'm going to do
um but if you don't have this all you
have to do is whatever IDE you're
developing yourp file in you need to
find the file path that it lives in and
then you need to find somewhere that
python.exe lives on your computer the
reality is when you install python
there's probably a folder like app data
or program files that has python
installed but whatever IDE you're
developing in If it creates virtual
environments for your projects it would
also have python installed in it so
we're going to copy this file path and
we're just going to open up notepad and
we are going to open an empty text file
and we're going to paste those file
paths in okay so I'm going to take the
first half of that up to python.exe I'm
going to put in one set of quotes So I
have my C users blah BL blah something
that will call python.exe and then in a
second set of quotes I'm going to put
the file path for the file that I
actually want to
run then really the only two things that
are specifically going to make this a uh
batch file a Windows batch file is you
want to tell Echo off and then at the
end you want to say pause so it doesn't
just blast through this line of code and
then immediately close the batch file
all right and now we have a text that's
this simple and we just hit file and
then save as and I'm going to put it on
the desktop and I'm going to save it on
my desktop and I'm going to call it
BeatMaker
dobat and this is the important part
that bat even though it's a text
document when you dobat you're telling
windows that it's a batch
file so if I hit save and then I did
already have it on there so I'll replace
it but if I hit save and I didn't have
it it would just put it on there I'm
going to close py charm so you guys can
see that it's not on there and now I
have this file with two little gears on
it on my desktop and it says beat maker
so I'm going to go ahead and double
click that and it says hello from py
game because that's what happens when
you boot up a python file with pame in
it and you can see it running and this
is immediately
functional okay so I have the high hat
the snare the
kicks and I'm just going to say this is
one of like my favorite python files
I've ever made um but you can see there
just by uh putting the python script
inside a batch file I've basically
turned it into an executable um which is
super easy so the last thing I want to
show is the easiest way to put that
batch file into something that's going
to automatically run when you start up
your computer and right before we get to
that I want to thank the SP onor of
today's video PCB way PCB way
manufactures highquality printed circuit
board and printed circuit board
assemblies for hobbyists and makers
their engineering staff reviews every
order to make sure it's accurate and
their sales and service team is
incredibly responsive and helpful they
have all sorts of cool customization
options including changing the color of
the boards themselves and the text that
you print onto your boards in addition
they have terrific 3D printing and metal
CNC prototyping Services their pricing
is super fair and their turnaround time
is great so thank you to PCB way for
sponsoring the video and be sure to
check them out in the link in the
description below the video now back to
the tutorial something that's going to
automatically run when you start up your
computer and to do this I do windows r i
open this run menu and then type shell
colon startup this is just the easiest
way to get to the folder that runs when
you start your computer up okay so you
hit enter on that and it brings you to a
folder and then all you have to do it's
this easy just contrl C on the the batch
file that you just made and drop it into
startup okay now the only way I can
really show you this working is me
taking a video with my phone while I
restart the computer so the video
editing might clip a little bit now so
that I can show you this uh booting up
on auto startup okay so I'm signed out
I'm going to uh put my pin
in and there's our batch file running
our script and it goes straight to the
program and we can start using it
immediately so just like that we've
created a file that can run on Startup
okay you guys so that is going to do it
for today's video I hope you found this
useful I hope it showed you exactly what
you're looking for when you clicked on
this video be sure to drop a comment
letting me know what you want to see
more of on the channel and if you had
any questions about what you saw here
today consider leaving a like on the
video subscribing to the channel it
helps me out a ton if you love the
content I'm making on the channel
consider becoming a Super supporter of L
Master Tech by checking out my patreon
link in the comments below as well thank
you so much for watching good luck with
your projects and we'll see you next
time thanks bye
