r/PythonLearning • • Oct 06 '26

im making a "you are an idiot" adjecent peice of code and currently am trying to get this to work

im using thonny with python 3.1.4.4 and have pygame-ce downloaded

heres the error code.
Traceback (most recent call last):

File "<string>", line 10, in <module>

File "file location.py", line 555, in run

with Popen(*popenargs, **kwargs) as process:

File "file location.py", line 1039, in __init__

self._execute_child(args, executable, preexec_fn, close_fds,

File "file location.py", line 1553, in _execute_child

hp, ht, pid, tid = _winapi.CreateProcess(executable, args,

FileNotFoundError: [WinError 2] The system cannot find the file specified

and heres the code

import pygame

import sys

import time

import random

import os

import sys

import subprocess;

a = []

if len(sys.argv) == 1 or sys.argv[1] != "1":

pythonPath = subprocess.run(["which","python3"], capture_output=True).stdout.strip();

print("python at",pythonPath)

#The i is num of windows, it will open +1 extra. stopping the code will close just the extra window

for i in range(9):

proc = subprocess.Popen(

[pythonPath,os.path.realpath(__file__),"1"]

)

a.append(proc)

print("spawned window")

import pygame

import sys

import time

import random

import os

import sys

import subprocess;

a = []

if len(sys.argv) == 1 or sys.argv[1] != "1":

pythonPath = subprocess.run(["which","python3"], capture_output=True).stdout.strip();

print("python at",pythonPath)

#The i is num of windows, it will open +1 extra. stopping the code will close just the extra window

for i in range(9):

proc = subprocess.Popen(

[pythonPath,os.path.realpath(__file__),"1"]

)

a.append(proc)

print("spawned window")

import pygame

import sys

import time

import random

import os

import sys

import subprocess;

a = []

if len(sys.argv) == 1 or sys.argv[1] != "1":

pythonPath = subprocess.run(["which","python3"], capture_output=True).stdout.strip();

print("python at",pythonPath)

#The i is num of windows, it will open +1 extra. stopping the code will close just the extra window

for i in range(9):

proc = subprocess.Popen(

[pythonPath,os.path.realpath(__file__),"1"]

)

a.append(proc)

print("spawned window")

0 Upvotes

3 comments sorted by

1

u/atarivcs Oct 06 '26

"which" is a unix command. I believe the windows command is "where".

1

u/Outrageous-Fish-8527 Oct 06 '26

tysm that worked! theres one more error though

"Traceback (most recent call last):

File "<string>", line 15, in <module>

NameError: name '__file__' is not defined"

do i name a file that?

1

u/atarivcs Oct 06 '26

In a normal python program, __file__ is an automatically defined variable that has the full pathname to the current python module.

But it looks like Thonny doesn't do it that way, so that variable does not exist.