Mac Python IDLE issue

Hello, whenever I have IDLE open, I can right click a python script in finder and open with IDLE. However, when IDLE is not already open, I get an error message saying “The document could not be opened.IDLE cannot open files in the python script format”. I have seen similar issues online but I am yet to find a solution that works.



Unfortunately, I have already checked System Preferences> Privacy settings and I can see Python is granted access to documents. Other posts online suggested this could be an OS issue; I tried upgrading to Monterey but the issue is still present.


I believe this entry from https://bugs.python.org/issue38946  summarises my issue best:


Now just to make things a bit more complicated - sigh: I also tested with the recent python.org installer for the 3.10.0a4 pre-release. The principal difference between the 3.9.1 and 3.10.0a4 versions I tested with is that the 3.9.1 is linked with Tk 8.6.10 while 3.10.0a4 is linked with the just-released Tk 8.6.11. On macOS 11 Big Sur, there is one noticeable difference in behavior between the two. With the macOS 11 Big Sur / 3.10.0a4 / 8.6.11 combo, when double-clicking on a .py file without IDLE.app being active, a message window appears saying that the application cannot open Python Script files but does launch IDLE.app. With IDLE.app now active, double-clicking again on the same file then does cause the file to be opened in an edit window of the active IDLE as expected and double-clicking on other .py files then open edit windows for them as expected. Without more detailed investigation, this appears to be a minor problem (possibly a change in Tk) unrelated to those in this issue other than that it involves double-clicking on .py files but I thought I should mention it here in case someone runs into it before it is resolved.

MacBook Pro (2020 and later)

Posted on Oct 31, 2021 8:57 AM

Reply

Similar questions

8 replies

Oct 31, 2021 6:50 PM in response to 12Shadow12

Well that thread you linked to was started almost two years ago, and says the issue was resolved before Monterey was ever released to anyone. That doesn't sound like Monterey is at all related. You tried it in Monterey too. (For the record, macOS system update NEVER fix bugs. If you apply a system update hoping to fix a bug, you are already on the wrong path.)


It isn't that there are incompatibilities, per se, between macOS and Python. This is just a bug in Python. There aren't very many people using IDLE on the Mac and most issues follow the same pattern as what you are currently experiencing. The developers are most likely unfamiliar with security developments on macOS over the past several years.


I went ahead and installed Python 3.10 in a factory-fresh VM to test it. It was easy to reproduce exactly what you are seeing. I can't say exactly what the problem is. I'm sure it is related to whatever funky things Python is doing. It actually installs two different apps (IDLE and Python Launcher) that are configured to open .py files. The Console log reported an error log due to different bundle IDs. I don't know if that is the cause of the problem or not. This is a standard open-source Mac problem. Somebody hacked something up years ago instead of doing it correctly. Maybe it has had other hacks over the years. But it was never done properly and now it exhibits strange behaviour.


I tried the exact same test in a different app and it worked fine. This is just a Python bug. It sounds like it hasn't worked properly since 2019, if not before. Nothing you can do to fix it except bug the Python developers.

Nov 1, 2021 7:02 AM in response to 12Shadow12

12Shadow12 wrote:

I've heard the universal python macos download is slightly 'experimental' for M1. I'm thinking about getting an exchange for MBP Intel i5 10th gen 1tb ssd and 16gb ram. It's slightly more expensive but my thought is that the Intel processor might handle python better?

No. Don't do that. This has nothing to do with the processor. I ran my test on an Intel machine.

Also, would you recommend swapping between Windows and MacOS, would Windows run slower or generally just as good?

My official recommendation would be to stop using IDLE. Clearly, it isn't supported by the developers and hasn't been for years. Python itself is fine, more or less. By that I mean it isn't any worse on the Mac than it is on Linux. I'm not really a Python fan. 😄


On the Mac, there is a large, virtually impassible, but invisible, line between the Unix-style tools and Mac-style tools. Virtually 100% of all the Unix-style tools and techniques from Solaris, Linux, etc. work just fine on the Mac, but only as long as you use them as you would on Solaris, Linux, etc. Whenever any developers from those other operating systems try to do something Mac-like, they always screw it up, and I mean always. Let them do the command-line stuff. That will all work fine. But if you want to integrate any of that world with your easy-to-use Mac interface, you have to rely on Mac developers.


If you wanted to use a Python environment on the Mac, I would recommend tools like BBEdit, Xcode, and maybe VSCode or Panic's new Nova. Personally, I don't know much about those last two. I know VSCode is popular among the hip young kids. Panic's tools have always been popular among old-school Mac users. For myself, I do small things in the Terminal with vim. Bigger files might need BBEdit. I use, at best 5% of BBEdit's capabilities. For bigger projects that really need an IDE, I'll use Xcode. For example, I build all of my web sites using XML, XSLT, and makefiles via Xcode.


For better or worse, this gap is growing. The switch to Apple Silicon is going to make it worse. That side might get better as Linux moves to ARM. But for the time being, you are going to have more and more problem getting open-source tools and techniques to run on the Mac.

Nov 1, 2021 8:35 AM in response to 12Shadow12

Don't fool with alpha/beta versions of Python. Use the released Python.org installer for your platform. I have an M1 mini running Big Sur 11.6.1 and Python 3.10 universal2 distribution works just fine. I only use IDLE (Python 2.7.16) if I am testing some code specific to that distribution, or Python/Objective-C with Apple's scripting bridge. Otherwise, I use IDLE3, again, only for testing if specific code works — before I continue building Python scripts in Sublime Text 4. I never attempt to open existing Python scripts in IDLE/3.


That programmer's editor also has a free plug-in, installable Python IDE package named Anaconda (not to be confused with the Anaconda Python distribution), and it reveals Python syntax and usage errors in line with your code. I find it invaluable.

Oct 31, 2021 5:13 PM in response to etresoft

Hello, thanks for that. Yes it does seem that there are points of incompatibility between macOS and python. However, I had been advised by someone that they had Monterey and this feature worked just fine for them (right click opening with IDLE regardless of whether IDLE was already open or not). This made me believe the issue lied with my settings configuration; having checked, I saw that Python has been granted access to documents (box is ticked). IDLE is also set as the default program for opening python script files. This is a shame as this is the most common troubleshooting solution that has been mentioned, upon looking at similar forum entries elsewhere. I recently switched from Windows to Mac and this has been one of the inconveniences I have been experiencing. I liked features of file explorer, such as being able to create a new file through right click, the 'move to' feature, easily accessing 'edit with idle' without the hassle, etc. On the other hand, the Macbook Pro runs faster and quieter, can run xcode, etc. I've found myself in a bit of a dilemma making the switch to macOS, mainly making the decision to purchase based on online recommendations that Mac is an all-round, good choice for programming.

Oct 31, 2021 4:23 PM in response to 12Shadow12

12Shadow12 wrote:

I believe this entry from https://bugs.python.org/issue38946  summarises my issue best:

But doesn't that thread also say this?


I am now running Mac OS X 11.2.3 with IDLE 3.9.1 (and pygame 2.0.1).

In this environment, the issue of opening files is completely fixed and works perfectly.


If that is wrong, then maybe you should update that thread.


Unfortunately, the Mac and open-source projects don't get along very well, especially when they try to go beyond the Terminal and into places like the Finder. The problem is that they hacked in some Finder support way back when and haven't kept it up-to-date. Then, when Apple makes significant changes to operating system security, and their apps stop working, they simply throw their hands up and blame Apple.


Apple has officially divested itself of any and all scripting environments. So if you are seeing a problem in Python that is now 100% Python's problem to solve. It sounds like a problem with file system permissions, most likely executable bits, and interactions with Gatekeeper.


Generally speaking, it is best to let scripting tools like this stay in the Terminal where they are comfortable. If you want to contribute to IDLE itself and fix the code, maybe you could try that, maybe not. But I'm afraid you are at an impasse. Apple people don't care and neither do Python people.

Nov 1, 2021 6:09 AM in response to etresoft

Again, thanks very much for taking the time to look into this. I am going to find a way of contacting Python about this but, obviously, my options might be quite limited as they are open source. As I have found my MBP to be superior to the Windows PC I was previously using, I am willing to negotiate as there is an easy workaround to this problem (opening IDLE first and then right click opening or directly opening with from within IDLE), also using visual studio works just fine with right click. However, I was intrigued as to why this was even a problem in the first place. The current model of mac I am using is M1 processor 8gb ram 512gb ssd . I've heard the universal python macos download is slightly 'experimental' for M1. I'm thinking about getting an exchange for MBP Intel i5 10th gen 1tb ssd and 16gb ram. It's slightly more expensive but my thought is that the Intel processor might handle python better? Or I can use bootcamp to switch between macos and Windows according to usage. Although, I see a lot of negative coverage about the MBPs with Intel processors, with suggestions they are slower, heat up easier, have inferior graphics, etc. Also, would you recommend swapping between Windows and MacOS, would Windows run slower or generally just as good?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Mac Python IDLE issue

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.