How do you fix this PermissionError "<frozen importlib._bootstrap>" in Terminal of MacBook?

Viewed 709

For some background information, I am using Python 3.9.1 on a MacBook Air. I have been using this MacBook Air for more than a year with no such problems. However, I tried to use the Terminal window like I normally do yesterday and I received an odd Permission Error message.

If I run% python3 (in order to enter command prompt), or >>> import requests, bs4, the following error message appears:

Python 3.9.1 (default, Dec 25 2020, 13:14:21) 
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
  File 
"/opt/homebrew/Cellar/python@3.9/3.9.1_2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site.py", line 418, in register_readline
    import readline
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 982, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 925, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1349, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1318, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1282, in _path_importer_cache
PermissionError: [Errno 1] Operation not permitted 

The odd thing is that the commands I showed above run properly if I ran them in Visual Studio Code and the Permission Error message appears only if I run them in the Terminal window. I would greatly appreciate it if anyone had any suggestions on how to fix this error.

1 Answers

This happened to me because I had moved my working directory into the Trash using the Finder in macOS.

As a consequence, running pwd in Terminal resulted in /Users/<username>/.Trash/<my_working_folder>, and macOS limits the privileges of programs run from the Trash.

Changing to a folder outside of the Trash before running python fixed the issue.

Related