Using the command line to make IDLE pop up with a filename.py to run; ie >>> idle filename.py

When submitting the above instruction in cmd line I get this error: " ‘idle’ is not recognized as an internal or external command." The idea is that the IDLE window pops up with filename.py code ready to run. I have tried changing the environment variables with no luck. Is this because pip and Python are located in different directories? I was trying to follow the RealPython video:
How to run code from the command line: https://www.youtube.com/watch?v=cAXfFyzi9Bo
I also tried adding “\Lib\idlelib” at the end in the environment variable path with no luck. Please help

From the command line, just do “python filename.py”.

If you want to edit the file with Idle (and then optionnally run it), you can do “python -m idlelib filename.py”.

André Roberge

1 Like

Hi Willem,

To start with, you need to tell us what operating system you are using,
because any answer is likely to depend on whether you are running
Windows, Linux, Mac OS or something else.

If running python -m idlelib filename works for you, that’s probably
the simplest way to do it. Otherwise, we’ll need more information:

  • what’s the OS?
  • what version of Python does running python -V give you?
  • if that the version you were expecting?
  • do you have an “idle” file at all? (try a local file search)
  • where is it?
  • what’s your path?
1 Like

Thank you so much, Andrè. That solved my problem!

1 Like

Hi Steven,
Yes, python -m idlelib filename worked on Windows. I suppose the same would work on Linux as well. I will try that out today. Should there be a searchable ‘IDLE’ file? Do you mean one that came with the Python installation, or one which I created? I didn’t create an ‘idle’ file

Hi Andre,
I am doing a course where we’re working on both Windows and Linux.
Your solution works fine on Windows, but I get an error on Linux:
I typed: python3 -m idlelib filename.py
I get: “usr/bin/python3: No module named idlelib”
If I use “idle” the error changes to: "can’t open file “idle”: [Errno 2] No such file or directory
Please help

I don’t use Linux. I suspect that Idle is not installed by default on your Linux-based computers. This seems to be common; see https://vitux.com/how-to-install-idle-python-ide-on-your-ubuntu/ for example.

Thanks Andrè,
I’ll check it out. It looks like a good resource
Muche appreciated