This project has moved and is read-only. For the latest updates, please go here.

Importing modules using relative path

Dec 16, 2013 at 12:41 AM
Hi! I'm new to PTVS. I just noticed that the intellisense doesn't work unless I type the project name first followed by the folder name, then followed by the python file.

I have a project with several folders. Inside the folders are python files. The structure is like this:
Inside module1, I need to import module3. When I type
from projName.folder2.module3 import something
it works. But it doesn't work when I start with relative path like this
from folder2.module3 import something
What should I do in order for me to import modules without specifying the project name first? so that non-PTVS users can also use my code (because it only uses relative paths).
Dec 16, 2013 at 5:39 AM
Do you have any files? Your behaviour makes sense if you have three of them (one in projName, folder1 and folder2) but you probably don't want one in projName.

This layout should behave as you expect:
   (no files)
Also, do those imports work when you run the code in Python? If so, have you set any search paths or PYTHONPATH values? Our aim is to match what Python does, and with default settings we should be correct for this case. However, we don't track all the possible ways that exist to add extra search paths to Python (and some are simply impossible), so it may be that your code works because of one of these.
Dec 16, 2013 at 10:20 PM
Hi Zooba, thank you very much!

You are right, the intellisense definitely works after I deleted the file inside projName.

To answer your question, yes the code runs ok when I use from folder2.module3 import something. I did specify "." in the search paths which I assume is the solution directory. I have also set some values in PYTHONPATH, i.e. the directory of my python installation and library packages.