FAQ
BlankCan't get import to work - need to know correct directory to put
.py files in for processing

I have just installed Python 2.2.1 under Windows 98SE (from a Computer
Shopper CD). I am working my way through the Tutorial, but cannot
import files for processing by IDLE. Where does IDLE expect to find
the named file (eg. prog.py), so that "import prog.py" will work?

I tried putting it various directories, such as /usr/local/bin
/usr/local/lib /usr/local/bin/python but none have worked. SO where
is the magic directory?

Caroline.

Search Discussions

  • David LeBlanc at May 23, 2002 at 12:05 am
    Try this:

    K:\python
    Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    import sys
    sys.path
    ['', 'J:\\Python22\\lib\\site-packages\\Pythonwin',
    'J:\\Python22\\lib\\site-packages\\win32', '
    J:\\Python22\\lib\\site-packages\\win32\\lib',
    'J:\\Python22\\lib\\site-packages', 'J:\\Python22
    \\DLLs', 'J:\\Python22\\lib', 'J:\\Python22\\lib\\lib-tk', 'J:\\Python22']
    >>>
    (this list will obviously look a bit different on a Linux/Unix box)

    Python will look for files in any of the listed directories. I'm surprised
    that putting "prog.py" in /usr/local/bin/python didn't make it accessable to
    Idle.

    David LeBlanc
    Seattle, WA USA
    -----Original Message-----
    From: python-list-admin at python.org
    [mailto:python-list-admin at python.org]On Behalf Of CarolineBlue
    Sent: Wednesday, May 22, 2002 16:19
    To: python-list at python.org
    Subject: Where does IDLE expect to find imported files?


    BlankCan't get import to work - need to know correct directory to put
    .py files in for processing

    I have just installed Python 2.2.1 under Windows 98SE (from a Computer
    Shopper CD). I am working my way through the Tutorial, but cannot
    import files for processing by IDLE. Where does IDLE expect to find
    the named file (eg. prog.py), so that "import prog.py" will work?

    I tried putting it various directories, such as /usr/local/bin
    /usr/local/lib /usr/local/bin/python but none have worked. SO where
    is the magic directory?

    Caroline.



    --
    http://mail.python.org/mailman/listinfo/python-list
  • Justin Shaw at May 23, 2002 at 1:12 am
    Python searches the $PYTHONPATH environmental variable which behaves like
    the $PATH variable. Try this:
    UNIX> setenv PYTHONPATH /home/caroline/python # or wherever
    prog.py is
    UNIX> python
    ...
    import prog
    prog.run() ...
    To make the module available to all users put it in (on Solaris default
    install) /usr/local/lib/python2.2/site-packages/

    Good luck!

    "CarolineBlue" <Midnightblue3 at btinternet.com> wrote in message
    news:ach90f$141$1 at knossos.btinternet.com...
    BlankCan't get import to work - need to know correct directory to put
    .py files in for processing

    I have just installed Python 2.2.1 under Windows 98SE (from a Computer
    Shopper CD). I am working my way through the Tutorial, but cannot
    import files for processing by IDLE. Where does IDLE expect to find
    the named file (eg. prog.py), so that "import prog.py" will work?

    I tried putting it various directories, such as /usr/local/bin
    /usr/local/lib /usr/local/bin/python but none have worked. SO where
    is the magic directory?

    Caroline.

  • Brad Bollenbach at May 23, 2002 at 1:24 am
    "CarolineBlue" <Midnightblue3 at btinternet.com> wrote in
    news:ach90f$141$1 at knossos.btinternet.com:
    BlankCan't get import to work - need to know correct directory to put
    .py files in for processing

    I have just installed Python 2.2.1 under Windows 98SE (from a Computer
    Shopper CD). I am working my way through the Tutorial, but cannot
    import files for processing by IDLE. Where does IDLE expect to find
    the named file (eg. prog.py), so that "import prog.py" will work?
    The details of where Python will look are platform specific.

    Generally, it will first look to see if the module is a builtin, and from
    there proceed to search sys.path to find the module you're trying to
    import. So, on my Windows ME box, sys.path can be examined as follows:
    import sys
    print sys.path
    ['', 'C:\\PYTHON22\\lib\\site-packages\\win32', 'C:\\PYTHON22\\lib\\site-
    packages\\win32\\lib', 'C:\\PYTHON22\\lib\\site-packages',
    'C:\\PYTHON22\\lib\\site-packages\\Pythonwin', 'C:\\PYTHON22\\DLLs',
    'C:\\PYTHON22\\lib', 'C:\\PYTHON22\\lib\\lib-tk', 'C:\\PYTHON22']
    >>>

    Hope that helps.


    --
    Brad Bollenbach
  • Ed LeBouthillier at May 24, 2002 at 4:32 am

    On Wed, 22 May 2002 23:18:39 +0000 (UTC), "CarolineBlue" wrote:

    BlankCan't get import to work - need to know correct directory to put
    .py files in for processing

    I have just installed Python 2.2.1 under Windows 98SE (from a Computer
    Shopper CD). I am working my way through the Tutorial, but cannot
    import files for processing by IDLE. Where does IDLE expect to find
    the named file (eg. prog.py), so that "import prog.py" will work?
    Given file "prog.py", don't "import prog.py", but rather "import prog"
    I tried putting it various directories, such as /usr/local/bin
    /usr/local/lib /usr/local/bin/python but none have worked. SO where
    is the magic directory?
    Python reads a system environment variable PYTHONPATH and
    appends it to sys.path. It then searches in the directories listed
    in sys.path. To make it look where you want it, add:

    set PYTHONPATH=C:\directory

    in your autoexec.bat file

    Cheers,
    Ed
  • John Machin at May 24, 2002 at 9:42 am
    "CarolineBlue" <Midnightblue3 at btinternet.com> wrote in message news:<ach90f$141$1 at knossos.btinternet.com>...
    BlankCan't get import to work - need to know correct directory to put
    .py files in for processing

    I have just installed Python 2.2.1 under Windows 98SE (from a Computer
    Shopper CD). I am working my way through the Tutorial, but cannot
    import files for processing by IDLE. Where does IDLE expect to find
    the named file (eg. prog.py), so that "import prog.py" will work?
    "import prog.py" won't work. You need merely "import prog". You are
    importing a module, not a file. The prog module may be found in a file
    called prog.py or prog.pyc or prog.pyd or prog.pyo or prog.whatever
    ...

    *Then* follow whatever advice you get about the Python path.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 22, '02 at 11:18p
activeMay 24, '02 at 9:42a
posts6
users6
websitepython.org

People

Translate

site design / logo © 2022 Grokbase