0

when I try to run python code on the command prompt, it automatically opens vs code. I want to run the code on the command prompt. How do I fix this?

This is the code:

import pyautogui as spam
import time

limit = int(input("Enter the number of messages you want to send: "))
msg = input("Enter the message you want to send: ")

time.sleep(3)

for i in range(0,limit+1):
    spam.typewrite(msg)
    spam.press("Enter")

enter image description here

enter image description here

António Rebelo
  • 186
  • 1
  • 13

2 Answers2

1

Your machine does not automatically executes python files with python but as default opens them with VS Code.

I assume you call it via "yourprogram.py". Call it with "python .\yourprogram.py"

hYg-Cain
  • 348
  • 3
  • 10
  • Hi, this works. However, is there a way that I can change it so that I can call it using "myprogram.py" and it not open vs code? Thank you so much either way – António Rebelo Mar 29 '22 at 23:01
  • 1
    I guess you didn't set the PATH variable when installing python. https://stackoverflow.com/questions/58754860/cmd-opens-window-store-when-i-type-python – hYg-Cain Mar 29 '22 at 23:05
  • The question is very different from the one I had. I don't really understand how it is relevant to me, could you please explain? – António Rebelo Mar 29 '22 at 23:09
  • Also, I have installed python three times by accident. The two extra I think I had some problems with python so I tried reinstalling it. I don't know if that is relevant or not. Would I need to uninstall two of them? If so, what is the best way of doing this? – António Rebelo Mar 29 '22 at 23:11
  • It sounds like you have (intentionally or not) configured Windows to associate the file extension `.py` with the VS Code application. – John Gordon Mar 29 '22 at 23:37
  • @JohnGordon Yes maybe I have, is there any way I can change it back to normal? – António Rebelo Mar 30 '22 at 09:05
  • look at the accepted answer from the post I mentioned in my comment. This should solve your issue. It's not the exact same problem since there windows store is opened but it is teh same root cause. Wrong PATH variable in windows and associationg set to VS Code instead of python3.exe – hYg-Cain Mar 30 '22 at 23:05
  • @hYg-Cain I only saw this now sorry. The accepted answer from the post you mentioned says to unselect the aliases for python. However, I have a lot of them and I am unsure on what to do. I will post a picture at the bottom of the question. It'd be great if you could help me – António Rebelo Apr 04 '22 at 19:49
  • this acutally looks ok, important are your windwos environment PATH variables. Check out this answer: https://stackoverflow.com/a/61010415/6074111 it is detailed with screenshots, I hope this helps to understand and resolve your issue. Note: in the solution they are fixing it for a different default (windows explorer) in your case you have to make sure that python.exe comes BEFORE Visual Studio Code – hYg-Cain Apr 05 '22 at 08:24
0

just set your machine to open .py archives with python end not VS Code

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 13 '23 at 09:59