Location of Python modules

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Byte

    #1

    Location of Python modules

    Pretty much self explanatry, where are Python modules stored in Linux?
    (i.e. in /usr/bin/local, or where?)

  • Szabolcs Nagy

    #2
    Re: Location of Python modules

    /usr/lib/python2.4/site-packages ?

    Comment

    • Byte

      #3
      Re: Location of Python modules

      No, not there

      -- /usr/bin/byte

      Comment

      • bruno at modulix

        #4
        Re: Location of Python modules

        Byte wrote:[color=blue]
        > Pretty much self explanatry, where are Python modules stored in Linux?
        > (i.e. in /usr/bin/local, or where?)
        >[/color]
        Depends on how you installed Python (or how your distro package system
        installed it). But it's usually in $PREFIX/lib/pythonX.X , with $PREFIX
        being one of /usr or /usr/local (third-part modules being in the
        site-packages subdirectory).

        --
        bruno desthuilliers
        python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
        p in 'onurb@xiludom. gro'.split('@')])"

        Comment

        • Fredrik Lundh

          #5
          Re: Location of Python modules

          "Byte" wrote:
          [color=blue]
          > Pretty much self explanatry, where are Python modules stored in Linux?
          > (i.e. in /usr/bin/local, or where?)[/color]

          it depends on how and where Python is installed. to see where they
          are on your install, use

          $ python -c "import sys; print sys.path"
          ['', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2',
          '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload',
          '/usr/local/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages', ...

          to check where a given module is installed, you can do

          $ python -c "import cgi; print cgi.__file__"
          /usr/lib/python2.4/cgi.pyc

          hope this helps!

          </F>



          Comment

          • wittempj@hotmail.com

            #6
            Re: Location of Python modules

            martin@jordaan: ~$ python
            Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
            They are in one of the directories listed in sys.path, for me this is:
            [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
            Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
            >>> import sys
            >>> print sys.path[/color][/color][/color]
            ['', '/usr/lib/python24.zip', '/usr/lib/python2.4',
            '/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk',
            '/usr/lib/python2.4/lib-dynload',
            '/usr/local/lib/python2.4/site-packages',
            '/usr/lib/python2.4/site-packages',
            '/usr/lib/python2.4/site-packages/HTMLgen',
            '/usr/lib/python2.4/site-packages/Numeric',
            '/usr/lib/python2.4/site-packages/PIL',
            '/usr/lib/python2.4/site-packages/cairo',
            '/usr/lib/python2.4/site-packages/gtk-2.0'][color=blue][color=green][color=darkred]
            >>>[/color][/color][/color]

            see http://docs.python.org/lib/module-sys.html

            Comment

            • Martin v. Löwis

              #7
              Re: Location of Python modules

              Byte wrote:[color=blue]
              > No, not there[/color]

              Sure:

              martin@mira:~$ ls /usr/lib/python2.4/site-packages
              apt debconf.py Numeric pygtk.py
              README
              apt_inst.so debconf.pyc Numeric.pth pygtk.pyc
              setuptools-0.6a8-py2.4.egg
              apt_pkg.so easy-install.pth ORBit.la pygtk.pyo
              setuptools.pth
              cairo FormEncode-0.4-py2.4.egg ORBit.so pygtk.py.python 2.4-gtk2
              cairo.pth gtk-2.0 pygtk.pth python-support.pth


              You mean, on *your* Linux? Give me an SSH account to your machine,
              and I find out for you.

              Regards,
              Martin

              Comment

              • Byte

                #8
                Re: Location of Python modules

                Found it in /usr/local/lib/python2.4/site-packages, thanks. Now, how do
                i convert a .py program into a module?

                -- /usr/bin/byte

                Comment

                • Fredrik Lundh

                  #9
                  Re: Location of Python modules

                  "Byte" <eoinrogers@gma il.com> wrote:
                  [color=blue]
                  > Found it in /usr/local/lib/python2.4/site-packages, thanks. Now, how do
                  > i convert a .py program into a module?[/color]

                  a .py program is a module (the module's content is what's left when the
                  program is finished).

                  to make a useful module, just make sure that it defines all the stuff you
                  want to make available (functions, classes, constants, etc), and that it
                  doesn't have any unexpected side-effects.

                  to create a script that can be used both as a script and as a module, you
                  can check the __name__ variable. see:

                  Python offers a wide range of modules to simplify complex tasks. Learn what a module is, how to utilize them, and how to create your own modules in Python.


                  for more on this.

                  </F>



                  Comment

                  • Szabolcs Nagy

                    #10
                    Re: Location of Python modules

                    LOL

                    a .py program is a module, you can import it:
                    if it is in the sys.path (import modulename).
                    if it sits in a directory that is in the sys.path and the directory
                    also has a __init__.py file (import dirname.modulen ame / from dirname
                    import modulname).
                    if there is a modulename.pth file in the sys.path containing the path
                    to your .py file.
                    (the current dir is always in the sys.path).

                    if you want to install your module (copy it under the site-packages
                    dir), then you should use distutils module and create a setup.py script

                    the compiled bytecode (.pyc file) is always automatically generated

                    Comment

                    • Rene Pijlman

                      #11
                      Re: Location of Python modules

                      Byte:[color=blue]
                      >where are Python modules stored in Linux?[/color]

                      Where are eggs laid on the western hemisphere?

                      --
                      René Pijlman

                      Comment

                      • Byte

                        #12
                        Re: Location of Python modules

                        >if it is in the sys.path

                        sys.path, what is this?

                        Comment

                        • Fredrik Lundh

                          #13
                          Re: Location of Python modules

                          Byte wrote:
                          [color=blue][color=green]
                          > >if it is in the sys.path[/color]
                          >
                          > sys.path, what is this?[/color]

                          a variable in the sys module. quoting from a reply that you might have
                          missed:

                          $ python -c "import sys; print sys.path"
                          ['', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2',
                          '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload',
                          '/usr/local/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages', ...

                          </F>



                          Comment

                          Working...