Py2app: Operation not permitted
Asked Answered
I

6

11

I want to create an application called 'dodgeball' and I have my main script (which uses pygame), and my setup.py script. I need an image named ball.bmp that I need as well.

Inside my setup.py script I have the following code: from setuptools import setup

APP = ['dodgeball.py']
DATA_FILES = ["ball.bmp"]
OPTIONS = {'argv_emulation': True}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

Whenever I try to make the application using the following stuff in Terminal:

python setup.py py2app

everything works up to

*** creating application bundle: dodgeball ***

then it returns an error:

error: [Errno 1] Operation not permitted: '/Users/**********/Desktop/Dodgeball/dist/dodgeball.app/Contents/MacOS/dodgeball'

If it helps, I'm on Mac OS X El Capitan (10.11). I'm aware that El Capitan, like any Apple update, will have new software and features that may break stuff like this.

QUESTION

How do I fix this error and then allow py2app to make a fully functionable app?

Ictus answered 18/10, 2015 at 11:27 Comment(3)
Maybe you should try running your command with sudoForeconscious
Thanks! It doesn't have the error anymore, but now when I try to open it it says "dodgeball error". :(Ictus
see also forums.developer.apple.com/thread/6987Mal
I
8

After I upgraded my operating system to OS X El Capitan (10.11.2), I got similar error when packaging my app using py2app:

*** creating application bundle: MyApp ***
error: [Errno 1] Operation not permitted: '/Users/jake/work/my-app/dist/MyApp.app/Contents/MacOS/MyApp'

I did some research and found a solution: 1) disable SIP; 2) remove restricted file flag on Python.framework. It worked for me.

Disable SIP

  1. Restart your Mac.

  2. Before OS X starts up, hold down Command+R and keep it held down until you see an Apple icon and a progress bar. Release. This boots you into Recovery.

  3. From the Utilities menu, select Terminal.

  4. At the prompt type the following:

    csrutil status
    csrutil disable
    reboot
    

You can re-enable SIP by following the above steps, but using:

csrutil enable

References:

Remove Restricted File Flag

sudo chflags -R norestricted /System/Library/Frameworks/Python.framework

As it's mentioned in https://forums.developer.apple.com/thread/6987

Interosculate answered 5/1, 2016 at 4:58 Comment(0)
S
8

I had the same problem. Instead of running

python setup.py py2app

I tried

python3 setup.py py2app

and it worked just fine. Hope this helps.

Synder answered 7/11, 2017 at 10:36 Comment(0)
H
3

Don't use the system provided py2app. Running this fixed the issue for me:

pip install --user --ignore-installed py2app

(I'm usually wary of things that require me to disable System Integrity Protection)

Hinson answered 18/6, 2017 at 16:49 Comment(1)
This is the better solution. I'd prefer not to disable SIP. This worked great for me.Freely
A
2

Solution: Install with -U flag!

Since all of you will have installed py2app already, start by uninstalling it.

pip3 uninstall py2app

After this point, it's crucial that you reinstall it using the -U flag! 📦

pip3 install -U py2app
py2applet --make-setup YourApp.py
python3 setup.py py2app -A

Look in your dist/ folder, there should now be a runnable application.

Then you can rebuild it using python3 setup.py py2app

Verified on OS X Catalina, Mojave, Big Sur

Auriga answered 12/5, 2020 at 10:52 Comment(0)
M
1

This doesn't happen if you build and install your own py2app rather than depending on the OS-bundled one.

Inside your virtualenv, install Mercurial (if needed), then:

pip install hg+https://bitbucket.org/ronaldoussoren/py2app/

py2app should then work without issue.

Merriott answered 19/12, 2015 at 18:53 Comment(1)
Edited my answer to clarify.Merriott
B
0

I had this same error on my Mac, version Sierra 10.12. My inspiration came from @Nicholas Riley's answer.

The context of my issue:

  • building a simple app using pandas and easygui
  • working in a virtualenv
  • setup.py was already generated by running $ py2applet --make-setup MyApplication.py
  • py2app was installed globally, but not yet in my virtualenv
  • virtualenv was not active

My solution:

activate the virtualenv

Spievats-MacBook-Pro:EasyGuiTest user$ source bin/activate

install py2app in the virtualenv

(EasyGuiTest) Spievats-MacBook-Pro:EasyGuiTest brady$ pip install py2app

run py2app again

(EasyGuiTest) Spievats-MacBook-Pro:EasyGuiTest brady$ python setup.py py2app -A

This worked perfectly! I hope it helps someone else.

Bruce answered 9/5, 2017 at 22:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.