[Tutor] Relative import help

Peter Otten __peter__ at web.de
Sat Sep 22 18:42:26 CEST 2012


Matthew Ngaha wrote:

>> You probably have a path that reaches into Domestic or Europe
>> sub-package. That can happen if e. g. Project/Domestic/Europe is your
>> current working directory.
>>
>> Try to cd into the Project folder's parent directory and see if
>>
>> $ python -c 'import Project.Domestic.Europe.winners'
>>
>> works.
> 
> ive got into the parent directory and typed this code both in cmd, and
>  my python file. niether seems to work. on idle i get invalid syntax
>  error. im on windows

You had forward slashes in your description of the folder layout, so I 
assumed you were on a linux box or a mac. I think I have now learned the 
lesson and will make fewer assumptions in the future.

First, in idle's "shell" window type

>>> import sys
>>> print(sys.executable)

(dont' type the ">>>", that will appear automatically) This should print 
something like

C:\python32\python3.exe

Now use Windows Explorer to navigate to the parent folder of "Project" and 
follow the instructions on

http://www.windows7hacker.com/index.php/2009/08/how-to-open-dos-prompt-
command-here-in-windows-7-and-more/

(hold the shift key and right-click, then choose [Open Command Window Here])

You should now see an ugly little black box. Type in 

C:\python32\python3 -c 'import Project.Domestic.Europe.winners'

but remember to replace C:\python32\python3 with the actual contents of 
sys.executable. 

Whew ;)






More information about the Tutor mailing list