[wingide-users] Changing Python Path from Script

Michael Foord fuzzyman at voidspace.org.uk
Sat Jan 13 08:27:08 MST 2007

Wingware Support wrote:
> On Sat, 13 Jan 2007, Michael Foord wrote:
>> All our imports are absolute imports based on the directory of our main 
>> script. This means that the Python path needs to be :
>>     Directory of main script
>>     Main Directory/Python24
>> We need this setting for autocomplete to work.
> Maybe this is useful in crafting a work-around for now:
> As John said, the dir of the main script should be added
> automatically so nothing should be needed here.
How ?

If I load the file :


How is 'Main' automatically added to the Python Path ?

>   Also, the
> location of the main debug file (as set from Debug menu) is
> stored in the project as a partial path, relative to the project
> location, so it should work when checking things out to different
> locations.
So every time we do a new checkout we need to create a new project file.

This is what I meant about dynamically creating/modifying project files.

We could solve this by having a project file in the main directory - but 
that means polluting the main directory of our repository. This isn't 
out of the question.

It still doesn't solve the problem of when we are working on two branches.

Say we have a file from a modified branch / checkout. We want to 
simultaneously load the same file from a fresh checkout to test how 
performance compares. Having a script that can switch the Python Path 
based on the location of the current file will solve that.

> For the second element, what about using an environment variable?  
> In project and file properties, anything in the form $(ENVNAME)
> is expanded out from the contents of the environment.  
> So it should work to define the Python Path element as
> $(MAINDIR)/Python24 and setting MAINDIR environment variable from
> the command or a shell script / batch file before launching Wing
> (the script/batch file could of course also launch Wing and open
> the project)
> This isn't ideal, but maybe it'll help...
It's not bad - if my script changes the environment variable 
appropriately then will wing switch to using the new value of the 
environment variable ? My guess is not, but at least I can switch the 
value at the command line and launch a new instance of Wing from the 
command line which *will* use the changed value.

All the best,


> - Stephan

More information about the wingide-users mailing list