[Tutor] Concerning relative import paths

Alan Gauld alan.gauld at btinternet.com
Tue Mar 15 05:46:38 EDT 2016


On 14/03/16 17:19, David Aldrich wrote:

> myproj ----- gui
> 
>          |
> 
>          |-- python
> 
> My gui/main.py contains this sort of import code:
> 
> import os, sys
> sys.path.append('../python')
> import MyClass
> 
> 
> The thing is that I am using Microsoft's Visual Studio...
> My question is: is there a better way that I can specify 
> the import statements so that a tool such as Intellisense
> will have an absolute path to find the modules?

I know nothing about VS but have you tried setting the
PYTHONPATH environment variable to myproj/python?
Then just use

import MyClass

If VS sees anything its probably the environment vars.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list