Re: [Boa Constr] running applications
Status: Beta
Brought to you by:
riaan
From: Misner, R. <rm...@ac...> - 2002-07-31 20:50:59
|
> By default applications use the same sys.path settings as Boa itself. = If=20 > I want to run my app using modules located in other paths - how would = I=20 > do that? It depends on these "other paths" and how they are used... On my system (WinXP / Python 2.2) Boa executes the script pointed to by = the PYTHONSTART environment variable. In my case, I have set up a = script called PythonStart.py in my home folder and set = PYTHONSTART=3DX:\PythonStart.py. In my PythonStart module, I import = sys, and call sys.path.append() for all the python module paths I want = to use. I find this is a good way to set up paths for my local = workstation, particularly to modules I have written to do specialized = shell-only functions that I used for experimentation and introspection. = But of course this method doesn't work if you need to set up these paths = for your application to run on somebody else's workstation. If these paths are dependant on your application rather than your = workstation, then you could just do some sys.path.append() calls at the = beginning of your application's main module. Then every time you run = it, it will set up the appropriate path. If these paths are relative to = your main application's directory, you can use code like this: in main.py: ------------------ import os import main as thismodule sThisFilePath =3D thismodule.__file__ sThisFileDir =3D os.path.split(sThisFilePath)[0] sPathToAdd =3D os.path.join(sThisFileDir, "MySubDir") os.path.append(sPathToAdd) -----end main.py------ However, if you are just trying to import or execute modules located = under your project directory tree, then you should consider setting up = your project as a python package. All you have to do is create an empty = file in each directory and subdirectory of your project and name it = __init__.py and it will cause the local directory (and all those in the = tree that have an __init__.py file) to be searched for modules before = the standard python path is searched. That way if you have a local = module in your project that has the same name as another module in the = sys.path, your local module is what will be loaded. You can read more = about packages on the python website. They explain it better than I = can. In windows, there is also a PYTHONPATH environment variable, which you = can try changing. I have not had any success changing it so I don't = think it is actually supported, but then maybe there was some other = problem going on that I didn't notice. Again, this is only for = workstation-specific paths. If you need your application to have access = to the directories in question when it is run on another machine, then = you can't use this method. I'm pretty new to Python so maybe somebody else has better ideas? Hope = this helped anyway... -Ris |