Solved

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

Posted on 2011-09-05
3
568 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
  • 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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…

809 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