Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

Not Able to Open Python File, IDLE Error Python 3.9.1

I am using a MacBook Pro with macOS Big Sur v 11.1.

Yesterday out of nowhere I was trying to open some Python files from my terminal (e.g. $open foo.py), and the following error and screenshot comes up:

enter image description here

When I try running this command using the terminal through Visual Studio code, I get an almost identical error message:

enter image description here

I have no idea how to go about this. One thing I tried running in a bash terminal:

bash-3.2$ python3
Python 3.9.1 (default, Dec 17 2020, 10:08:12) 
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> import idlelib.idle
macOS 11 or later required !
Abort trap: 6

I do not understand this error message, as I have macOS 11.1.

EDIT: in addition to not being able to open any .py files, I am also unable to run any .py files either (e.g. $python3 foo.py will not output anything even if it is supposed to).

I am able to open any other file type without any issue, even Jupyter Notebooks (.ipybn extension), it is only .py files that will not open.

One thing that could have happened: I was doing a practice interview and wrote a script called testInterview.py for it. Because I cannot open the file, I cannot paste the code, but it implements a function that takes an array A as an input and determines the smallest positive value that is not in that array. I'm new to Python, so after working on it I tried to figure out how I could run it from the command line myself, and ran the following in my terminal:

$python3 -c 'import testInterview; print testInterview.Solution(A = [1, 3, 4, 5])'

Nothing output in my terminal (it should have returned a value of 2), but it did create a __pycache__ directory. At the time I did not know what this was and figured it was just an extra file created by me running the function, so I tried removing it. Only after trying to remove it did I run into the current issue.

question from:https://stackoverflow.com/questions/65951153/not-able-to-open-python-file-idle-error-python-3-9-1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After downloading Python from the website, the problem seems to have been fixed. I'm not sure why, but there seems to be a lot of bugs in Apple's version of Python, and they occurred because I did not download it from the Python website to begin with (I used Homebrew). See here for more information.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...