Solved

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

Posted on 2011-09-05
3
576 Views
Last Modified: 2012-05-12
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()

Open in new window


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'])

Open in new window


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

Open in new window


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
0
Comment
Question by:imperialguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
gelonida earned 500 total points
ID: 36485082
First thing you should do is print out the path as seen by python.

import os
os_path = os.environ['PATH']
print os_path.split(':')

It might give you some idea of what is going wrong.

In the very worst case you could even change PATH in python and only then perform your sys calls.

os.environ['PATH'] = '/path/to/my/tools"' + os.environ['PATH']
0
 

Assisted Solution

by:imperialguy
imperialguy earned 0 total points
ID: 36485271
@gelonida

I found out that the path seen by the python interpreter when the script is run from command-line is the desired path. But, the path seen by the interpreter when the GUI Mac app is launched is a different one. So, I changed the path in the `/.MacOSX/environment.plist using the Property LIst Editor. I added the '/Devloper/usr/bin' to the environment.plist file and restarted the Mac. This time it recognized cvs and hence the problem is solved now. Thanks for your help.
0
 

Author Closing Comment

by:imperialguy
ID: 36515671
I found out that the path seen by the python interpreter when the script is run from command-line is the desired path. But, the path seen by the interpreter when the GUI Mac app is launched is a different one. So, I changed the path in the `/.MacOSX/environment.plist using the Property LIst Editor. I added the '/Devloper/usr/bin' to the environment.plist file and restarted the Mac. This time it recognized cvs and hence the problem is solved now.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question