Module Import Path?

  • Thread starter Brian van den Broek
  • Start date
B

Brian van den Broek

Jesse B. said unto the world upon 31/07/2004 15:42:
I have just begun to learn python using o'reilly's Learning Python, and in
chapter 3 it talks about importing modules. It has me make modules to
practice using the 'import' and 'from' statements from the python command
line.

I don't know what directory to save these files in because I'm not sure what
directories 'import' is looking in to find modules. I've done some google
searches trying to find out where the 'import' search path is, but I'm not
familiar enough with python to do a clear enough search. I'd appriciate it
if anyone can help me out or point me in the right direction.

Hi,

import sys
sys.path

will tell you how your Python Path is configured.

On windows, you can configure your Python path by including a line like:

SET PYTHONPATH=D:\PYPATHDir1;C:\PYPATHDir2

in your Autoexec.bat file. Just be sure not to put any spaces around the
'=' and to separate multiple directories with ';' characters.

Some windows versions (not mine, so I cannot say exactly what to do) allow
you to set the PythonPath environment variable via the Control Panel.

Best,

Brian vdB
 
B

Brian van den Broek

Jesse B. said unto the world upon 31/07/2004 15:42:
I have just begun to learn python using o'reilly's Learning Python, and in
chapter 3 it talks about importing modules. It has me make modules to
practice using the 'import' and 'from' statements from the python command
line.

I don't know what directory to save these files in because I'm not sure what
directories 'import' is looking in to find modules. I've done some google
searches trying to find out where the 'import' search path is, but I'm not
familiar enough with python to do a clear enough search. I'd appriciate it
if anyone can help me out or point me in the right direction.

Hi,

Typing too quickly, I wrote
import sys
sys.path

will tell you how your Python Path is configured.

Not everything returned by sys.path is there because of your PYTHONPATH
environment variable. For instance, the first entry is the one from which
your running script was loaded. Likewise, the standard Library Dirs are
there, too. Check out the sys module documentation for the full details.

Best,

Brian vdB
 
P

Paramjit Oberoi

I have just begun to learn python using o'reilly's Learning Python, and in
chapter 3 it talks about importing modules. It has me make modules to
practice using the 'import' and 'from' statements from the python command
line.

If you are doing the imports from the interpreter, put the modules in the
current directory. In case of a script, use the directory that the script
is in.
 
J

Jesse B.

I have just begun to learn python using o'reilly's Learning Python, and in
chapter 3 it talks about importing modules. It has me make modules to
practice using the 'import' and 'from' statements from the python command
line.

I don't know what directory to save these files in because I'm not sure what
directories 'import' is looking in to find modules. I've done some google
searches trying to find out where the 'import' search path is, but I'm not
familiar enough with python to do a clear enough search. I'd appriciate it
if anyone can help me out or point me in the right direction.
 
J

Jesse B.

Thank you for the quick response, this was driving me alittle nuts. I
appreciate the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top