module name not recognized

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

    #1

    module name not recognized

    I have built two basic modules using distutils. One of them installs fine,
    but the other, I can't import modules from it. I've been pouring over the
    code and I cant find the problem.

    I know the file has been copied to site-packages/mypackage, but I cant do

    from mypackage import mymodule

    Could I get suggestions as to why a module would be installed but not
    registered?

    Thanks,
    Darren
  • Larry Bates

    #2
    Re: module name not recognized

    Darren Dale wrote:[color=blue]
    > I have built two basic modules using distutils. One of them installs fine,
    > but the other, I can't import modules from it. I've been pouring over the
    > code and I cant find the problem.
    >
    > I know the file has been copied to site-packages/mypackage, but I cant do
    >
    > from mypackage import mymodule
    >
    > Could I get suggestions as to why a module would be installed but not
    > registered?
    >
    > Thanks,
    > Darren[/color]

    Two things to check:

    Does the package have the required __init__.py file?
    Is the directory where it is installed on the PYTHONPATH?

    Larry Bates

    Comment

    • Darren Dale

      #3
      Re: module name not recognized

      Larry Bates wrote:
      [color=blue]
      > Darren Dale wrote:[color=green]
      >> I have built two basic modules using distutils. One of them installs
      >> fine, but the other, I can't import modules from it. I've been pouring
      >> over the code and I cant find the problem.
      >>
      >> I know the file has been copied to site-packages/mypackage, but I cant do
      >>
      >> from mypackage import mymodule
      >>
      >> Could I get suggestions as to why a module would be installed but not
      >> registered?
      >>
      >> Thanks,
      >> Darren[/color]
      >
      > Two things to check:
      >
      > Does the package have the required __init__.py file?
      > Is the directory where it is installed on the PYTHONPATH?
      >
      > Larry Bates[/color]

      Thanks Larry,
      I checked both before writing the original post, this isnt the problem.



      Comment

      • Jeffrey Froman

        #4
        Re: module name not recognized

        Darren Dale wrote:
        [color=blue]
        > Could I get suggestions as to why a module would be installed but not
        > registered?[/color]

        If the permissions are incorrect on the module files, then some users may be
        unable to import the modules.

        Jeffrey

        Comment

        • Alan Kennedy

          #5
          Re: module name not recognized

          [Darren Dale][color=blue][color=green][color=darkred]
          >>>I have built two basic modules using distutils. One of them
          >>> installs fine, but the other, I can't import modules from it.
          >>> I've been pouring over the code and I cant find the problem.[/color][/color][/color]

          [Larry Bates][color=blue][color=green]
          >>Two things to check:
          >>
          >>Does the package have the required __init__.py file?
          >>Is the directory where it is installed on the PYTHONPATH?[/color][/color]

          [Darren Dale][color=blue]
          > I checked both before writing the original post, this isnt the
          > problem.[/color]

          One more thing to check: have you named your module with an identical
          name to an existing module that is before your module the path, e.g.
          calling your module "xml" or "email", which clash with standard
          library modules. This is a frequent cause of hair-pulling inexplicable
          behaviour.

          If that isn't the problem either, then you're probably best off
          posting more details, i.e. what are your modules called, where are
          they located, what doesn't work/what exceptions are raised, etc.

          regards,

          alan.

          Comment

          • Fredrik Lundh

            #6
            Re: module name not recognized

            Darren Dale wrote:
            [color=blue]
            >I have built two basic modules using distutils. One of them installs fine,
            > but the other, I can't import modules from it. I've been pouring over the
            > code and I cant find the problem.
            >
            > I know the file has been copied to site-packages/mypackage, but I cant do
            >
            > from mypackage import mymodule[/color]

            really? do you mean that you could type that into your mail program, but
            not into a Python program? that's weird... (read on)
            [color=blue]
            > Could I get suggestions as to why a module would be installed but not
            > registered?[/color]

            if you run python with the -vv option, it tells you where it looks.

            $ python -vv
            ...[color=blue][color=green][color=darkred]
            >>> from mypackage import mymodule[/color][/color][/color]
            # trying mypackage.so
            # trying mypackage.py
            # trying mypackage.pyc
            ...

            btw, note that if that import finds a mypackage without a mymodule,
            it says

            ImportError: cannot import name mymodule

            if it cannot find mypackage itself, it says

            ImportError: No module named mypackage

            (this is why you should *always* include tracebacks when asking about
            an error... "can't do" or "doesn't work" or "an error" or even "an import
            error" doesn't contain all the information you have, so you're forcing us to
            guess. don't do that, if you can avoid it)

            </F>



            Comment

            • Darren Dale

              #7
              Re: module name not recognized

              Fredrik Lundh wrote:
              [color=blue]
              > Darren Dale wrote:
              >[color=green]
              >>I have built two basic modules using distutils. One of them installs fine,
              >> but the other, I can't import modules from it. I've been pouring over the
              >> code and I cant find the problem.
              >>
              >> I know the file has been copied to site-packages/mypackage, but I cant do
              >>
              >> from mypackage import mymodule[/color]
              >
              > really? do you mean that you could type that into your mail program, but
              > not into a Python program? that's weird... (read on)
              >[color=green]
              >> Could I get suggestions as to why a module would be installed but not
              >> registered?[/color]
              >
              > if you run python with the -vv option, it tells you where it looks.
              >
              > $ python -vv
              > ...[color=green][color=darkred]
              > >>> from mypackage import mymodule[/color][/color]
              > # trying mypackage.so
              > # trying mypackage.py
              > # trying mypackage.pyc
              > ...
              >
              > btw, note that if that import finds a mypackage without a mymodule,
              > it says
              >
              > ImportError: cannot import name mymodule
              >
              > if it cannot find mypackage itself, it says
              >
              > ImportError: No module named mypackage
              >
              > (this is why you should *always* include tracebacks when asking about
              > an error... "can't do" or "doesn't work" or "an error" or even "an import
              > error" doesn't contain all the information you have, so you're forcing us
              > to
              > guess. don't do that, if you can avoid it)
              >
              > </F>[/color]

              Sorry, I thought the subject line would be enough information. You are
              right. The relevant ouput from python -vv is below. Distutils installed the
              package to /usr/lib/python2.3/site-packages/simCTR, but python is looking
              only in the directory of my test script:


              # trying /home/darren/temp/simCTR/fresnel.so
              # trying /home/darren/temp/simCTR/fresnelmodule.s o
              # trying /home/darren/temp/simCTR/fresnel.py
              # trying /home/darren/temp/simCTR/fresnel.pyc
              Traceback (most recent call last):
              File "temp.py", line 7, in ?
              from simCTR.fresnel import *
              ImportError: No module named fresnel


              Why doesnt python check in /usr/lib/python2.3/site-packages/simCTR? It does
              so for the other package I built. Here is the contents of the
              site-packages/simCTR directory:

              -rw-r--r-- 1 root root 1248 Oct 10 12:56 __init__.py
              -rw-r--r-- 1 root root 1952 Oct 10 12:56 __init__.pyc
              -rw-r--r-- 1 root root 7805 Oct 8 16:00 fresnel.py
              -rw-r--r-- 1 root root 8062 Oct 10 12:51 fresnel.pyc
              -rw-r--r-- 1 root root 10235 Oct 8 16:00 kinematic.py
              -rw-r--r-- 1 root root 14011 Oct 10 12:51 kinematic.pyc
              -rw-r--r-- 1 root root 3795 Oct 5 12:53 spaceGroups.py
              -rw-r--r-- 1 root root 4381 Oct 10 12:51 spaceGroups.pyc


              Thanks,
              Darren

              Comment

              • Darren Dale

                #8
                Re: module name not recognized

                Darren Dale wrote:
                [color=blue]
                > I have built two basic modules using distutils. One of them installs fine,
                > but the other, I can't import modules from it. I've been pouring over the
                > code and I cant find the problem.
                >
                > I know the file has been copied to site-packages/mypackage, but I cant do
                >
                > from mypackage import mymodule
                >
                > Could I get suggestions as to why a module would be installed but not
                > registered?
                >
                > Thanks,
                > Darren[/color]


                Here is some more information. I tried changing the name of my package. It
                was called simCTR, and stored in the simCTR directory, and installed
                accordingly by distutils. import statements fail because the directory of
                my test script is searched during the import request, but the site-packages
                directory is not.

                I renamed the package to simctr, installed, and the import statements
                succeed. I didnt want to make this name change permanent, so I deleted the
                site-packages/simctr directory, tried to install simCTR again, and it
                fails.

                /usr/lib/python2.3/site-packages/simCTR:
                total 64
                -rw-r--r-- 1 root root 1248 Oct 10 12:56 __init__.py
                -rw-r--r-- 1 root root 1952 Oct 10 12:56 __init__.pyc
                -rw-r--r-- 1 root root 7805 Oct 8 16:00 fresnel.py
                -rw-r--r-- 1 root root 8062 Oct 10 12:51 fresnel.pyc
                -rw-r--r-- 1 root root 10235 Oct 8 16:00 kinematic.py
                -rw-r--r-- 1 root root 14011 Oct 10 12:51 kinematic.pyc
                -rw-r--r-- 1 root root 3795 Oct 5 12:53 spaceGroups.py
                -rw-r--r-- 1 root root 4381 Oct 10 12:51 spaceGroups.pyc

                /usr/lib/python2.3/site-packages/simctr:
                total 64
                -rw-r--r-- 1 root root 1248 Oct 10 13:17 __init__.py
                -rw-r--r-- 1 root root 1952 Oct 10 13:19 __init__.pyc
                -rw-r--r-- 1 root root 7805 Oct 10 13:17 fresnel.py
                -rw-r--r-- 1 root root 8062 Oct 10 13:19 fresnel.pyc
                -rw-r--r-- 1 root root 10235 Oct 10 13:17 kinematic.py
                -rw-r--r-- 1 root root 14011 Oct 10 13:19 kinematic.pyc
                -rw-r--r-- 1 root root 3795 Oct 10 13:17 spaceGroups.py
                -rw-r--r-- 1 root root 4381 Oct 10 13:19 spaceGroups.pyc


                Thanks,
                Darren

                Comment

                • Robert Kern

                  #9
                  Re: module name not recognized

                  Darren Dale wrote:
                  [color=blue]
                  > # trying /home/darren/temp/simCTR/fresnel.so
                  > # trying /home/darren/temp/simCTR/fresnelmodule.s o
                  > # trying /home/darren/temp/simCTR/fresnel.py
                  > # trying /home/darren/temp/simCTR/fresnel.pyc
                  > Traceback (most recent call last):
                  > File "temp.py", line 7, in ?
                  > from simCTR.fresnel import *
                  > ImportError: No module named fresnel[/color]

                  Don't execute python from /home/darren/temp .

                  --
                  Robert Kern
                  rkern@ucsd.edu

                  "In the fields of hell where the grass grows high
                  Are the graves of dreams allowed to die."
                  -- Richard Harter

                  Comment

                  • Darren Dale

                    #10
                    Re: module name not recognized

                    Robert Kern wrote:
                    [color=blue]
                    > Darren Dale wrote:
                    >[color=green]
                    >> # trying /home/darren/temp/simCTR/fresnel.so
                    >> # trying /home/darren/temp/simCTR/fresnelmodule.s o
                    >> # trying /home/darren/temp/simCTR/fresnel.py
                    >> # trying /home/darren/temp/simCTR/fresnel.pyc
                    >> Traceback (most recent call last):
                    >> File "temp.py", line 7, in ?
                    >> from simCTR.fresnel import *
                    >> ImportError: No module named fresnel[/color]
                    >
                    > Don't execute python from /home/darren/temp .
                    >[/color]

                    I see. I had two problems. I didnt realize there was an old simCTR directory
                    in ~/temp. Python was searching this directory, and when it didnt find the
                    module it raised an error. I read that python would try the current
                    directory first, and if that failed it would try other places along the
                    python search path. The caveat is that if python finds a package but not
                    the module, it will not continue the search. Thank you everyone, especially
                    Robert and Alan.

                    Comment

                    Working...