This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IDLE.app fails on macOS 10.15 if denied access to Documents
Type: crash Stage:
Components: IDLE, macOS Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: dd789, lvwarren, ned.deily, ronaldoussoren, terry.reedy
Priority: normal Keywords:

Created on 2020-03-10 23:11 by dd789, last changed 2022-04-11 14:59 by admin.

Messages (20)
msg363860 - (view) Author: dd (dd789) Date: 2020-03-10 23:11
I just upgraded my Mac OS to 10.15.3 and Python 3.8.2 install went fine.  But IDLE doesn't launch at all. I have already gone to System Preferences and allowed it to allow apps from anywhere.  When I go to the command line and do Python 3 I see the correct version.

But clicking on the IDLE app does nothing.  And previous python scripts don't run at all and I don't see errors.

Super grateful to anyone who may know the answer!
msg363861 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-03-10 23:15
Try running IDLE from the command line:

python3.8 -m idlelib

If that works, then open the Console.app, select the system log, and then try double-clicking the IDLE.app icon again and see if any messages appear there.
msg363862 - (view) Author: dd (dd789) Date: 2020-03-10 23:21
Thanks @ned.deily

That did not work.
>>> python3.8 -m idlelib
  File "<stdin>", line 1
    python3.8 -m idlelib
           ^
SyntaxError: invalid syntax

Also see this error on the system log
>>> python3.8 -m idlelib
  File "<stdin>", line 1
    python3.8 -m idlelib
           ^
SyntaxError: invalid syntax
msg363863 - (view) Author: dd (dd789) Date: 2020-03-10 23:23
I see this error in the system.log
Mar 10 17:18:25 DDs-MacBook-Pro com.apple.xpc.launchd[1] (org.python.IDLE.4188[1295]): Service exited with abnormal code: 1
msg363864 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-03-10 23:23
You need to first exit out of the Python interpreter back to the Unix shell.  Type:

quit()

Then try:

python3.8 -m idlelib
msg363865 - (view) Author: dd (dd789) Date: 2020-03-10 23:29
Thanks!  That way IDLE does open.

See this in the System log
Mar 10 17:26:24 DDs-MacBook-Pro diagnosticd[1289]: Posting stream filter: "{
	    global = 47245099008;
	}"
Mar 10 17:26:24 DDs-MacBook-Pro diagnosticd[1289]: System mode client started - Console (1418) - mode: 0xb, filter: "<empty>"
Mar 10 17:26:36 DDs-MacBook-Pro Console[1418]: assertion failed: 19D76: libxpc.dylib + 95826 [51E3E807-9133-3605-BB5F-D59ED6404ABF]: 0x89
msg363866 - (view) Author: dd (dd789) Date: 2020-03-10 23:31
Is the Unix shell the only way to open IDLE from now on?  Seems like I can get it to open that way, but clicking on the app like I used to no longer works.  Thank you so much!
msg363867 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-03-10 23:35
No, clicking on the app *should* work. I'm assuming you installed Python 3.8.2 from the python.org macOS installer?  If so, you *could* try reinstalling it again. For what it's worth, I am not aware of any current problems with launching the app on 10.15.x; it works for me :(
msg363868 - (view) Author: dd (dd789) Date: 2020-03-10 23:39
Yes, installed Python from the mac installer on this page.  I have done it multiple times already without any success. 

This is the error I keep seeing
Mar 10 17:39:23 DDs-MacBook-Pro com.apple.xpc.launchd[1] (org.python.IDLE.4188[1615]): Service exited with abnormal code: 1
msg363869 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-03-11 00:03
That message just means that Python terminated with an error; the specific traceback is lost.

But I just noticed one possible explanation. It appears that if the Files & Folder security setting is set to disallow access to your Documents Folder, IDLE.app will fail on startup but it will launch from the command line. Check the following in System Preferences.

Apple Menu (upper left corner) -> System Preferences -> Security & Privacy.
Then click on the Privacy tab, scroll to and click on Files and Folders, then look for a Python.app (not IDLE.app) entry.  It should have a Documents Folder entry underneath it and it should be checked (enabled). If not, click it (you might need to click on the lock in the lower left corner to enable changes).
msg363871 - (view) Author: dd (dd789) Date: 2020-03-11 00:14
Thank you so much Ned Deily, that was it!  FIXED IT!  You're awesome!!!
msg363872 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-03-11 00:29
Thanks for bringing it up!  That was a new failure mode we haven't seen before.

I was going to close this issue but then it struck me that we might be able to handle this situation a bit better; we should be able to catch an exception when IDLE tries to set the working directory to Documents.  I'll leave it up to you, Terry, if you want to pursue this.  I won't have time myself right now but maybe someone else would be willing to jump in.  It may be a little tricky to test and certainly requires a macOS 10.15.x Catalina system.
msg363885 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-11 06:25
Ned> we should be able to catch an exception when IDLE tries to set the working directory to Documents.

If IDLE did that, then I would consider the silent exit an IDLE bug.  However, IDLE only calls os.chdir, when running a user script, in the user process, to change to the script directory, so imports work as expected.  (In other words, to imitate what Python does.)  There are only proposals, #22121 and #28775, to IDLE itself to change IDLE's working directory when starting.

I presume a. that the switch results from how Python and IDLE are installed and how the icon is configured and b. that it happens before the first IDLE code is executed.  If so, there is nothing IDLE can do.
msg363886 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-03-11 07:12
Actually, IDLE *does* call os.chdir set the working directory when launched from IDLE.app on macOS:

https://github.com/python/cpython/blob/master/Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py#L8

While it's not in the idlelib directory, it's very much part of IDLE :)
msg363984 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-11 23:17
idlemain.py should be documented within idlelib* (I will do that, README.txt and maybe macosx.py).  Currently, the chdir is only part of idle.app, not idle on Mac, because it does not happen when starting IDLE in Terminal.  This is confusing.  As near as I can tell, it is not needed in idlemain.py.  If so, it should be moved (revised) into idlelib startup code so it always runs on Mac.  How about something like:

try:
    os.chdir(os.path.expanduser('~/Documents'))
except OSError:  # I presume
    <display tk  message box: cannot access Documents, explain how to change>
    os.chdir(os.path.expanduser('~'))  # Can this fail?

* The only mention of 'IDLE.app' in idlelib is in the news item for #27310, where you mention 'idlemain.py', sans path.
msg364049 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-03-12 21:16
Note that IDLE.app sets the current working directory to ~/Documents to have a sane working directory (and hence sane behavior in file dialogs), by default app bundles on macOS are launched with the root directory as the current working directory. 

For "python3 -m idlelib" it is not really necessary to change the working directory, and changing it might confuse users that also use IDLE on other platforms.
msg364066 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-03-13 02:16
As Ronald notes, the chdir to the user’s Documents folder is *only* needed when launching via IDLE.app (for example by double-clicking an IDLE.app icon in the macOS Finder) because the user has no control over the launched app’s working directory in that case and the default is inappropriate. Whereas, when launching IDLE from a command line (for example, with “python -m idlelib’), IDLE inherits the working directory of the UNIX shell process which the user has complete control over. This is how users experience IDLE today on all UNIXy platforms. Thus, the chdir location is correct and current code and behavior should not be changed except to catch a chdir failure. The only question is what to do when an exception is caught.
msg364069 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-13 03:10
Right.  I rechecked and Terminal starts in /Users/<username> and a user can easily switch to Documents or anything else.  Dialogs open in the same directory.  IDLE should stay wherever when started from terminal. That was agreed on #22121  (Checking 'sys.stdout is None' should work.)

Will my suggested change work in idlemain.py?  Is there any issue with importing tkinter.messagebox there?

If the solution for #22121 is an all-systems patch (see msg364068), as I now expect, the chdir in idlemain could be deleted.
msg364187 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-14 17:47
The solution given by Ned above also solved https://stackoverflow.com/questions/60648250/cannot-open-idle-on-mac.  So dd's situation was not unique.
msg398758 - (view) Author: Van Warren (lvwarren) Date: 2021-08-02 11:58
If you are running from a conda python library and don't want the weight of Jupyter for a quick python hack, add this to your .bashrc file (or equivalent shell startup)

alias idle='python -m idlelib'

This will bypass faulty default MacOS installs in /usr/local/bin

Ref: https://www.urbandictionary.com/define.php?term=hack
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84108
2021-08-02 11:58:41lvwarrensetnosy: + lvwarren
messages: + msg398758
2020-03-14 17:47:20terry.reedysetmessages: + msg364187
2020-03-13 03:10:26terry.reedysetmessages: + msg364069
2020-03-13 02:16:09ned.deilysetmessages: + msg364066
2020-03-12 21:16:20ronaldoussorensetmessages: + msg364049
2020-03-11 23:17:44terry.reedysetmessages: + msg363984
2020-03-11 07:18:37ned.deilysetassignee: terry.reedy ->
2020-03-11 07:12:34ned.deilysetassignee: terry.reedy
messages: + msg363886
components: + IDLE, - Installation
2020-03-11 06:29:31terry.reedysettitle: IDLE.app fails to launch on macOS 10.15 if denied access to user's Document Folder -> IDLE.app fails on macOS 10.15 if denied access to Documents
2020-03-11 06:25:14terry.reedysetnosy: + ronaldoussoren
messages: + msg363885

assignee: terry.reedy -> (no value)
components: + Installation, macOS, - IDLE
2020-03-11 00:29:47ned.deilysettype: crash
title: IDLE 3.8.2 doesn't launch on Catalina 10.15.3- HELP Service exited with abnormal code: 1 -> IDLE.app fails to launch on macOS 10.15 if denied access to user's Document Folder
messages: + msg363872
versions: + Python 3.7, Python 3.9
2020-03-11 00:14:09dd789setmessages: + msg363871
2020-03-11 00:03:33ned.deilysetmessages: + msg363869
2020-03-10 23:41:11dd789settitle: IDLE 3.8.2 doesn't launch on Catalina 10.15.3- HELP -> IDLE 3.8.2 doesn't launch on Catalina 10.15.3- HELP Service exited with abnormal code: 1
2020-03-10 23:39:54dd789setmessages: + msg363868
2020-03-10 23:35:05ned.deilysetmessages: + msg363867
2020-03-10 23:31:49dd789setmessages: + msg363866
2020-03-10 23:29:12dd789setmessages: + msg363865
2020-03-10 23:23:40ned.deilysetmessages: + msg363864
2020-03-10 23:23:00dd789setmessages: + msg363863
2020-03-10 23:21:37dd789setmessages: + msg363862
2020-03-10 23:15:53ned.deilysetnosy: + ned.deily
messages: + msg363861
2020-03-10 23:11:19dd789create