I am using py2app to bundle a python script, that uses the anaconda python distribution.
Since py2app doesn't play well with terminal scripts that need user input, I have a Tkinter file that py2app's setup.py launches, which then further launches my .py script using popen.
Locally, this works fine:
import subprocess as sub
command = "~/anaconda/bin/python -u myscript.py " + str(groups_count)
process = sub.Popen(command, shell=True, stdout=sub.PIPE, stderr=sub.PIPE, bufsize=1, universal_newlines=True)
But when I want to distribute this, I need to replace hardcoded paths and run this using the distribution contained within
import subprocess as sub
command = sys.executable + " -u myscript.py " + str(groups_count)
process = sub.Popen(command, shell=True, stdout=sub.PIPE, stderr=sub.PIPE, bufsize=1, universal_newlines=True)
This results in an error:
/bin/sh: /Users/username/projectname/appname/dist/MyOSXapp.app/Contents/MacOS/python: Permission denied
If I look at libpython2.7.dylib within /MyOSXapp.app/Contents/Frameworks it doesn't seem to be executable, but is readable by everyone. This is all assembled by py2app.
I need to run popen
on my anaconda python distributed within pyapp. How do I do this?
I worked around this by adding executable permission to the python
file saved by py2app within the osx .app file.
$ chmod +x ./dist/MyOSXapp.app/Contents/MacOS/python
Additionally, a fix for this was also added in py2app via issue 228.