Dist-packages and sys.path

I have some code inside myapplication that looks for some files in myapplications directories. I am working with AptanaStudio and I can see that my code is working fine, but when I create a debian package and I install it on another computer, the search fails because the sys.path looks like a different list.

From Aptana's execution, the sys.path includes the path to the executable directory (/ mysvncopy / myapplication) and I believe my code finds files this way.

Installing the app leaves these files in the / usr / share / pyshared / myapplication directory and I thought that this directory is automatically available for / usr / local / lib / python 2.6 / dist-packages in sys.path, but something is wrong , / usr / local / lib / python2.6 / dist-packages IS in sys.path of course, but the app doesn't find anything inside / usr / share / pyshared / myapplication.

How can I assure that the application knows what to look for inside / usr / share / pyshared / myapplication and equivalently inside windows and mac ?.

If I include in my code:

<sys.path.append('/usr/share/pyshared/myapplication')

      

search is successful, but this code is SO dependent.

You can paste setup.py if needed.

thank

+3


source to share


2 answers


I'm not familiar with using setup.py, so it might not be useful, but ..

If you import both sys and os at the top of your installer, you can do something like this:

if sys.getwindowsversion():
    <install to Windows dir>
elif os.system('uname -a'):
    ostest = os.popen('uname -a').split(' ')
    if str('Linux') in ostest:
        <install to Linux dir>

      



etc. I don't have a Mac, so I don't know if uname -a returns anything in one, but if it does, you can parse ostest for something like OSX (which will most likely be in there somewhere). And have a separate file or set of files for each OS. Or even simpler, after they are set, for example, some lines in your source files called "OSREPLACE" and then use something like this code, continuing from the part above, after finding os and assigning it as a variable:

...    
if os == 'linux':
    NEWSTRING = 'linuxpaths'
elif os == 'mac':
    NEWSTRING = 'macpaths'
elif os == 'windows':
    NEWSTRING = 'windowspaths'

for file in files:
        with open(str(file), 'r') as f:
            data = f.read()
            data = data.replace('OSREPLACE', 'NEWSTRING')
        with open(str(file), 'w') as f:
            f.write(data)       

      

0


source


If you are building a debian package containing a python application you should probably package it with pex ( https://github.com/pantsbuild/pex ) or cx_Freeze ( http://cx-freeze.sourceforge.net / ). This way your application always starts :)



0


source







All Articles