QA Graphic

Running Python on the Command Line

Fixing MacOS error with Python3

Python3 Monitor

Have you ever run into a problem executing a python3 file where you would get the following error:

  • OSError: cannot open resource
  • env: python3: Operation not permitted
  • python3: bad interpreter: Operation not permitted.

Easy Fix

Changes are you have the following header in that Python file:

#!/usr/bin/env python3

To make it work, change the header to:

#!/usr/bin/env /usr/bin/python3

Reasoning

This is probably happening because Python3 is not pointing to the right version of Python3.

The easy fix, is put in the full path of Python3. For most installations, it should be /usr/bin/python3. (Apple does a good job of keeping up with the current Python version.)

File Permissions

One last thing...

If your still having problems, make sure that the file permissions are set correctly.

chmod 755 filename.py

  Filed under the Bash category. - Permalink

About

Some useful Bash tips and tricks that I have learned over the years.