Search code examples
pythonpython-2.7wing-ide

Cannot get suggestions when importing Python file from another folder (Wing IDE)


I have a Python file called caller.py located at C:\Temp. I have two other Python files: local_testlib.py located in C:\Temp and testlib.py located in C:\Temp\MyLibs.

I am trying to import both of those files in Wing IDE Pro.

import sys
sys.path.append(r'C:\Temp\MyLibs')
import testlib #located in C:\Temp\MyLibs
import local_testlib #located in C:\Temp

#check suggestions by Wing
local_testlib. #get suggestions as list of variables etc. from the file
testlib. #don't get any suggestions

print testlib.myvar #get variable value printed OK

I get suggestions only for the local_testlib, nothing for the testlib (see picture below). I do get access to the variables in the testlib.py (so it is imported correctly) though. What adjustments should I have done to make this work?

enter image description here


Solution

  • To solve this you can add C:\Temp\MyLibs to your Python Path in Wing's Project Properties (or Configure Python dialog in Wing 101). Or in Wing Personal or Pro you can set the file as the main debug file, although I just noticed that you'll need to restart Wing before that approach works due to apparent failure to rescan the file.

    This could probably be changed to take local path modifications into account in our source analysis, although in general modifying sys.path like this is not a great way to do things since the added path may screw up other modules you import later if they are trying to import a module called testlib from another location. That's why we only look for modifications like this in the main debug file.

    You may want to instead make MyLibs into a package by adding a file called init.py inside it and then you can do this:

    from MyLibs import testlib

    That solves it w/o any extra configuration in Wing IDE.