[Tutor] Problem importing modules.

Alan Gauld alan.gauld at btinternet.com
Mon Jun 3 09:56:09 CEST 2013


On 03/06/13 07:09, Shreyas Prakash wrote:
> I am using Python 2.7
>
> I tried importing a module named hello.py
>
> I got this error message
>
> Traceback (most recent call last): File "", line 1, in import hello
> ImportError: No module named hello
>
> I am not sure why, Can you please give me more insight about the proper
> syntax and the PYTHONPATH directory.


Please use plain text emails otherwise the formatting gets all messed up 
(as in the error message above)

The most likely problem is that the folder containing hello.py is not in 
your import path. You can fix that by changing your PYTHONPATH 
environment variable or by modifying sys.path.

If you are using Windows then the PYTHONPATH solution is documented in 
my tutor in the Getting Started topic. It describes how to set PATH but 
the process for PYTHONPATH is exactly the same.

Otherwise tell us which OS you are using and we can help.
(Or Google environment variable for your OS, there are lots of web pages 
that describe the process!)

hth
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list