troubleshooting Question

cvs command not found by a Python Mac app created using py2app

Avatar of imperialguy
imperialguyFlag for United States of America asked on
Python
3 Comments1 Solution816 ViewsLast Modified:
OS: Mac OS X 10.7.1
Python: Active Python 2.7.2.5
wxPython: wxPython2.9-osx-2.9.1.1-cocoa-py2.7

I have a small wxpython-based Mac app that just tests the availability of cvs and svn on a Mac platform. This is the python code on which the Mac app is based on:

import wx
import commands,os

ID_RUN_BUTTON=1
class Frame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(100, 100),style=wx.MINIMIZE_BOX | wx.CLOSE_BOX)

        self.run_button=wx.Button(self,ID_RUN_BUTTON,label='Run')
        
        self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON)
        
        self.Centre()
	self.Show()
        
    def OnRun(self,evt):
	home_dir=os.path.expanduser("~")
        a=commands.getoutput("cvs")
	b=commands.getoutput("svn help")
	f=open('%s/cvs_test' % (home_dir),'w')
	f.write(a)
	f.write('\n')
	f.write(b)
	f.close()
            
if __name__ == '__main__':
    app = wx.App(redirect=False)
    frame = Frame(None, -1, 'CVS Tester')
    app.MainLoop()

Here is a screen shot of this simple GUI with one button called 'Run'.
screen shot of the simple cvs test app with a single 'Run' buttonOn pressing 'Run' it executes the OnRun method and it saves the output of the two commands 'cvs' and 'svn help' into a file in the home directory. When I run this code using the python interpreter on command-line, the output of both the commands is spit into a text file (attached cvs_test_1 file). As you can see, both cvs and svn commands are recognized and the output is as expected.

Now the problem is when I create a Mac app using py2app with the following script:

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['cvs_test.py']
DATA_FILES = [('icons',['./icons/ark-2.png'])]
OPTIONS = {'iconfile': './icons/ark-2.icns'}

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

The Mac app is created absolutely fine. But, when I open the Mac app and hit the 'Run' button, it says:

"sh: cvs: command not found"

The attached file cvs_test_2 is the output of Mac app.

The Mac app is obviously running the same script but it couldn't find the cvs command.

In my home directory, the following are the contents of my .profile file:

export TERM="xterm"
export PATH='/Developer/usr/bin':$PATH
export PATH='/usr/local/bin':$PATH

I added the path /Developer/usr/bin' by following a trick posted on Apple forums (click here) to resolve the cvs issue on OS X Lion.

What causes the python script to identify cvs when run from command-line and not identify it when the same script is run as a compiled Mac app ?

This question is killing me. My bash and the sh both of them can find cvs when run from the terminal, but the Mac app can't. Any suggestions would be greatly appreciated.
cvs-test-1
cvs-test-2
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros