Import, site packages, my modules, Windows vs. Linux

Discussion in 'Python' started by John Ladasky, Jun 4, 2008.

  1. John Ladasky

    John Ladasky Guest

    Hi folks,

    Running Python 2.5 on both a Windows XP laptop, and an Ubuntu Linux
    7.04 desktop.

    I've gotten tired of maintaining multiple copies of my personal
    modules that I use over and over. I have copies of these files in the
    same directory as the main program I happen to be working on at the
    time. I've also downloaded FANN, and want to use its Python
    bindings. FANN does not seem to build automatically, like wxWidgets
    did.

    These two issues have led me to examine exactly how the import
    statement works, how the PYTHONPATH environment variable is
    constructed, and how to change it.

    On Windows I found a solution that works, but which may be a kludge.
    In the Python "site-packages" folder, I added a sub-folder called "my-
    packages". Then I created a text file, "my-packages.pth", containing
    the single line, "my-packages." Finally, I moved my common personal
    modules into the my-packages folder and deleted all of my clumsy
    duplicates. Import statements now work for all of my files on the
    Windows box, great!

    I then tried to use this same strategy in Linux, and saw that I don't
    automatically have the privileges needed to alter the site-packages
    folder. On my Windows box, my default account has Administrator
    privileges. On Linux I can, of course, use sudo to modify the site-
    packages folder. But the fact that I would have to use sudo has me
    asking -- is there something inappropriate, or unsafe in my approach?

    I want to know what is the *recommended* way to integrate my own
    personal modules with Python. Thanks!
    John Ladasky, Jun 4, 2008
    #1
    1. Advertising

  2. John Ladasky

    John Ladasky Guest

    On Jun 3, 6:52 pm, Ben Finney <>
    wrote:
    > John Ladasky <> writes:
    > > I want to know what is the *recommended* way to integrate my own
    > > personal modules with Python. Thanks!

    >
    > You want the 'distutils' documentation
    > <URL:http://www.python.org/doc/lib/module-distutils> and the documents
    > that it references, which will lead you to write a 'setup.py' module
    > for your package.



    Many thanks, Ben, distutils was exactly what I needed. It was a
    little strange to grasp the concept that I would be "distributing" my
    module to myself -- but once I got over that mental hurdle, it worked
    perfectly.
    John Ladasky, Jun 4, 2008
    #2
    1. Advertising

  3. John Ladasky

    Terry Reedy Guest

    "John Ladasky" <> wrote in message
    news:...
    | On Windows I found a solution that works, but which may be a kludge.
    | In the Python "site-packages" folder, I added a sub-folder called "my-
    | packages". Then I created a text file, "my-packages.pth", containing
    | the single line, "my-packages." Finally, I moved my common personal
    | modules into the my-packages folder and deleted all of my clumsy
    | duplicates. Import statements now work for all of my files on the
    | Windows box, great!
    |
    | I then tried to use this same strategy in Linux, and saw that I don't
    | automatically have the privileges needed to alter the site-packages
    | folder. On my Windows box, my default account has Administrator
    | privileges.

    If you do the Windows install for all users, all users can add packages to
    site-packages -- as long as adding the package directory comprises the
    whole installation process and no registry fiddling is required.
    Terry Reedy, Jun 5, 2008
    #3
  4. John Ladasky

    rzed Guest

    John Ladasky <> wrote in
    news:.
    com:

    > Hi folks,
    >
    > Running Python 2.5 on both a Windows XP laptop, and an Ubuntu
    > Linux 7.04 desktop.
    >
    > I've gotten tired of maintaining multiple copies of my personal
    > modules that I use over and over. I have copies of these files
    > in the same directory as the main program I happen to be working
    > on at the time. I've also downloaded FANN, and want to use its
    > Python bindings. FANN does not seem to build automatically,
    > like wxWidgets did.
    >
    > These two issues have led me to examine exactly how the import
    > statement works, how the PYTHONPATH environment variable is
    > constructed, and how to change it.
    >
    > On Windows I found a solution that works, but which may be a
    > kludge. In the Python "site-packages" folder, I added a
    > sub-folder called "my- packages". Then I created a text file,
    > "my-packages.pth", containing the single line, "my-packages."
    > Finally, I moved my common personal modules into the my-packages
    > folder and deleted all of my clumsy duplicates. Import
    > statements now work for all of my files on the Windows box,
    > great!
    >
    > I then tried to use this same strategy in Linux, and saw that I
    > don't automatically have the privileges needed to alter the
    > site-packages folder. On my Windows box, my default account has
    > Administrator privileges. On Linux I can, of course, use sudo
    > to modify the site- packages folder. But the fact that I would
    > have to use sudo has me asking -- is there something
    > inappropriate, or unsafe in my approach?
    >
    > I want to know what is the *recommended* way to integrate my own
    > personal modules with Python. Thanks!


    I can't speak about Linux, but on Windows, you really should move
    your code out of the Python directory tree, I believe. When you
    upgrade, you'll have to be sure to set it up the same way again,
    and remember that your code resides there before you wipe out that
    directory tree, etc.

    Instead, just set up another directory containing your code and add
    that to your PYTHONPATH environment variable string. That will be
    unaffected by the Python version you're running, and will be
    available for multiple versions, if you run more than one.

    --
    rzed
    rzed, Jun 7, 2008
    #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. Peter Saffrey

    Python site-packages and import

    Peter Saffrey, Apr 29, 2005, in forum: Python
    Replies:
    1
    Views:
    1,079
    Maurice LING
    Apr 29, 2005
  2. Peter Saffrey

    Python site-packages and import

    Peter Saffrey, Apr 29, 2005, in forum: Python
    Replies:
    2
    Views:
    719
    Maurice LING
    Apr 30, 2005
  3. peter
    Replies:
    2
    Views:
    293
    peter
    Jul 12, 2005
  4. alf
    Replies:
    1
    Views:
    264
    Fredrik Lundh
    Nov 2, 2006
  5. defn noob
    Replies:
    10
    Views:
    512
    satoru
    Jul 5, 2008
Loading...

Share This Page