[wingide-users] Changing Python Path from Script

Wingware Support support at wingware.com
Thu Jan 11 11:00:45 MST 2007

On Thu, 11 Jan 2007, Michael Foord wrote:
> We need to setup the project Python Path dynamically.
> We sometimes work from several different branches, and we'd like to be 
> able to just set the Python Path from a script based on the current file 
> path.
> Sorry to be a nuisance. How do we set the project Python Path from the 
> scripting API ?

Do you mean for running the script or in general?  Wing can store 
a different path for each file, as accessed from the File 
Properties in Wing.  That is used for debugging as well as source 
analysis if the file is specified as the main file in the 
project or (I think) when working in that file.

If you want to set the path only during running, can't the script 
the you wrote to execute code do that?

In general, needing to set python path for each file like this
raises red flags for me.  This is likely to cause you pain in the
future whenever using or deploying the code. Maybe there's a
better solution, for example redesigning things so this isn't

If you must to set the File Properties automatically, you'ld have
to call a function similar to gApplication.GetAttribute() where
you call SetValue on the attribute manager instead (there isn't a
way to set attributes via the API yet and we'll probably add
specific API rather than access to attributes in general, tho I'm
not sure yet).  The attribute in question is proj.attribs.kPyPath
and it is used with a key for the file "location" (Wing's
internal way of storing paths or files or urls).

So usage would be something like this untested code:

  import proj.attribs
  import wingapi
  from wingutils import location

  filename = "/path/to/my/file"
  mypythonpath = "fdjkd:fdsfds:fdsfds:yadayada"

  loc = location.CreateFromName(filename)
  fa = wingapi.gApplication.fSingletons.fFileAttribMgr
  fa.SetValue(proj.attribs.kPyPath, loc, mypythonpath)

Hope this helps.  I'd still consider redesigning code so it runs 
without a unique python path for each script.

Stephan Deibel

Wing IDE for Python
Advancing Software Development


More information about the wingide-users mailing list