Search code examples
pythonpython-3.xwindowsbatch-fileexecution

How to make python 3 scripts execute from .bat file on Windows 10?


Very new to programming even newer to asking on stackoverflow so apologies if badly worded and/or formatted.

I'm using Python 3.7.2 on Windows 10. I'm trying to make .bat files so I can execute my python code without having to go into IDLE.

My python code is

#! python
import webbrowser
webbrowser.open('https://killsixbilliondemons.com/')

and the .bat file reads

@ C:\Program Files (x86)\Python37-32\python.exe C:\Users\User\Desktop\Codes\PROGS\mapIt.py

When I run it a command prompt window momentarily opens then closes but nothing happens in my browser. What's going wrong?


Solution

  • The line import webrowser contains a typo, it should be import webbrowser. Fixing that line should fix your issue.

    Furthermore, if you want to see the output of a .bat file, try running it from a pre-made cmd prompt by hitting windows + r, entering cmd in the prompt that appears, going to the directory the .bat file is in through the cd <FULLPATH> command and calling it through <NAMEOFBATFILE>.bat.