The answer

Discussion in 'Python' started by Jive Dadson, Jan 18, 2010.

  1. Jive Dadson

    Jive Dadson Guest

    Okay, with your help I've figured it out. Instructions are below, but
    read the caveat by Ben Fenny in this thread. All this stuff is good for
    one default version of Python only. The PYTHONPATH described below, for
    example, cannot specify a version number. Yes, that's a pain in the
    butt, but there's no way around it. If you switch versions, you may
    have to delete all the .pyc files that will show up in the module
    folders. Python ought to check them to see if they are valid, but I do
    not know if it does so.

    These instructions are for MS Windows.

    1) Create your modules folder. Let's say it's named "Modules." The
    documentation calls it a "package."

    2) In an explorer window or on the desktop, right click on My Computer,
    and select Properties.

    3) Select the Advanced tab, and click on Environment Variables near the
    bottom.

    4) Look for an environment variable named PYTHONPATH.

    a) If you do not find one, create one using the New button(s). I
    don't know if it has to be in User Variables or System Variables. To
    save time experimenting, I just put one in both. For the value, put the
    full path of the folder Modules.

    b) If there's already a PYTHONPATH, Edit it, adding a semi-colon
    and the full path of folder Module to the end.

    5) Put your module folders into the folder Module.

    6) (Here's a really arcane bit.) Into each module folder, put a file
    named __init__.py. It will be executed when you load the module. It
    can be empty, but it has to be there or else the module folder will be
    ignored.
     
    Jive Dadson, Jan 18, 2010
    #1
    1. Advertising

  2. Jive Dadson

    alex23 Guest

    On Jan 18, 12:30 pm, Jive Dadson <> wrote:
    > These instructions are for MS Windows.
    >
    > 1) Create your modules folder. Let's say it's named "Modules."  The
    > documentation calls it a "package."
    >
    > 2) In an explorer window or on the desktop, right click on My Computer,
    > and select Properties.
    >
    > 3) Select the Advanced tab, and click on Environment Variables near the
    > bottom.
    >
    > 4) Look for an environment variable named PYTHONPATH.
    >
    >     a) If you do not find one, create one using the New button(s). I
    > don't know if it has to be in User Variables or System Variables.  To
    > save time experimenting, I just put one in both. For the value, put the
    > full path of the folder Modules.
    >
    >     b) If there's already a PYTHONPATH,  Edit it, adding a semi-colon
    > and the full path of folder Module to the end.
    >
    > 5) Put your module folders into the folder Module.
    >
    > 6) (Here's a really arcane bit.) Into each module folder, put a file
    > named __init__.py.  It will be executed when you load the module.  It
    > can be empty, but it has to be there or else the module folder will be
    > ignored.


    Actually, if you're using Python 2.6+/3.x, you can effectively skip
    steps 1-5, as these versions now support user site-packages.

    Rather than create a Module folder and modify your PYTHONPATH, add (if
    it doesn't exist already) the following folder:
    %APPDATA%/Python/Python26/site-packages

    Modules can sit directly in the folder, or within packages.

    For more details: http://www.python.org/dev/peps/pep-0370/
     
    alex23, Jan 18, 2010
    #2
    1. Advertising

  3. Jive Dadson

    Lie Ryan Guest

    On 01/18/10 13:30, Jive Dadson wrote:
    > Okay, with your help I've figured it out. Instructions are below, but
    > read the caveat by Ben Fenny in this thread. All this stuff is good for
    > one default version of Python only. The PYTHONPATH described below, for
    > example, cannot specify a version number. Yes, that's a pain in the
    > butt, but there's no way around it. If you switch versions, you may
    > have to delete all the .pyc files that will show up in the module
    > folders. Python ought to check them to see if they are valid, but I do
    > not know if it does so.


    Err... "The answer" to... what?
     
    Lie Ryan, Jan 18, 2010
    #3
  4. Jive Dadson

    samwyse Guest

    On Jan 17, 8:30 pm, Jive Dadson <> wrote:
    > Okay, with your help I've figured it out.  Instructions are below, but
    > read the caveat by Ben Fenny in this thread.  All this stuff is good for
    > one default version of Python only.  The PYTHONPATH described below, for
    > example, cannot specify a version number.  Yes, that's a pain in the
    > butt, but there's no way around it.  If you switch versions, you may
    > have to delete all the .pyc files that will show up in the module
    > folders.  Python ought to check them to see if they are valid, but I do
    > not know if it does so.
    >
    > These instructions are for MS Windows.
    >
    > 1) Create your modules folder. Let's say it's named "Modules."  The
    > documentation calls it a "package."
    >
    > 2) In an explorer window or on the desktop, right click on My Computer,
    > and select Properties.
    >
    > 3) Select the Advanced tab, and click on Environment Variables near the
    > bottom.
    >
    > 4) Look for an environment variable named PYTHONPATH.
    >
    >     a) If you do not find one, create one using the New button(s). I
    > don't know if it has to be in User Variables or System Variables.  To
    > save time experimenting, I just put one in both. For the value, put the
    > full path of the folder Modules.
    >
    >     b) If there's already a PYTHONPATH,  Edit it, adding a semi-colon
    > and the full path of folder Module to the end.
    >
    > 5) Put your module folders into the folder Module.
    >
    > 6) (Here's a really arcane bit.) Into each module folder, put a file
    > named __init__.py.  It will be executed when you load the module.  It
    > can be empty, but it has to be there or else the module folder will be
    > ignored.


    In your original thread, you never quite said why you can't use site-
    packages and .pth files. Are you not allowed to modify your local
    installation? If you are writing something for distribution to
    others, then site-packages and .pth files are the best way to go,
    since they don't assume any particular operating system. If you can't
    (or won't) use them, then just create Module as a sub-directory of
    wherever your program lives, since that directory is always prepended
    to PYTHONPATH. If you need to use the same module from multiple
    directories, most modern operating systems support symbolic links; if
    you're using Windows, well, here's a nickel kid, get yourself a better
    computer (http://farm1.static.flickr.com/
    89/240711122_f9888e5a3b_o.jpg).

    I don't think that __init__.py is very arcane, since it is described
    in detail in the documentation. It's also a great place to use the
    standard site.addsitedir() function, which is another platform
    independent way to manipulate Python's search path.
     
    samwyse, Jan 18, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Coyne  Gaijin42
    Replies:
    0
    Views:
    615
    Jason Coyne Gaijin42
    Apr 2, 2004
  2. Jason Coyne  Gaijin42
    Replies:
    0
    Views:
    428
    Jason Coyne Gaijin42
    Apr 4, 2004
  3. Richard Blewett
    Replies:
    0
    Views:
    496
    Richard Blewett
    Oct 31, 2004
  4. ALuPin

    Modelsim Directory Answer

    ALuPin, Dec 9, 2004, in forum: VHDL
    Replies:
    0
    Views:
    512
    ALuPin
    Dec 9, 2004
  5. ALuPin
    Replies:
    1
    Views:
    420
    Ralf Hildebrandt
    Jan 6, 2005
Loading...

Share This Page