FAQ
After installing numpy, scipy, and matplotlib for python 2.6 and
running the code from http://www.scipy.org/Cookbook/OptimizationDemo1
(stored as xoptimize.py) in a directory with other python codes, I got
the error messages

C:\python\code\mycode>python xoptimize.py
Traceback (most recent call last):
File "xoptimize.py", line 3, in <module>
from pylab import *
File "c:\python26\lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "c:\python26\lib\site-packages\matplotlib\__init__.py", line
133, in <module>
import sys, os, tempfile
File "c:\python26\lib\tempfile.py", line 34, in <module>
from random import Random as _Random
File "C:\python\code\mycode\random.py", line 1, in <module>
from RandomArray import standard_normal
File "C:\python\code\mycode\RandomArray.py", line 1, in <module>
import ranlib
ImportError: No module named ranlib

When I create a new directory, copy xoptimize.py there, and run, the
program works. Can someone explain why other files are "interfering"
in the first case? Thanks.

Search Discussions

  • Chris Gonnerman at Nov 13, 2010 at 2:12 pm

    On 11/13/2010 07:52 AM, Beliavsky wrote:
    After installing numpy, scipy, and matplotlib for python 2.6 and
    running the code from http://www.scipy.org/Cookbook/OptimizationDemo1
    (stored as xoptimize.py) in a directory with other python codes, I got
    the error messages

    C:\python\code\mycode>python xoptimize.py
    Traceback (most recent call last):
    File "xoptimize.py", line 3, in<module>
    from pylab import *
    File "c:\python26\lib\site-packages\pylab.py", line 1, in<module>
    from matplotlib.pylab import *
    File "c:\python26\lib\site-packages\matplotlib\__init__.py", line
    133, in<module>
    import sys, os, tempfile
    File "c:\python26\lib\tempfile.py", line 34, in<module>
    from random import Random as _Random
    File "C:\python\code\mycode\random.py", line 1, in<module>
    from RandomArray import standard_normal
    File "C:\python\code\mycode\RandomArray.py", line 1, in<module>
    import ranlib
    ImportError: No module named ranlib

    When I create a new directory, copy xoptimize.py there, and run, the
    program works. Can someone explain why other files are "interfering"
    in the first case? Thanks.
    You'd need to post a list of the files in the directory before we'd have
    any idea why this is happening.

    -- Chris.
  • Benjamin Kaplan at Nov 13, 2010 at 2:27 pm

    On Saturday, November 13, 2010, Chris Gonnerman wrote:
    On 11/13/2010 07:52 AM, Beliavsky wrote:

    After installing numpy, scipy, and matplotlib for python 2.6 and
    running the code from http://www.scipy.org/Cookbook/OptimizationDemo1
    (stored as xoptimize.py) in a directory with other python codes, I got
    the error messages

    C:\python\code\mycode>python xoptimize.py
    Traceback (most recent call last):
    ? File "xoptimize.py", line 3, in<module>
    ? ? from pylab import *
    ? File "c:\python26\lib\site-packages\pylab.py", line 1, in<module>
    ? ? from matplotlib.pylab import *
    ? File "c:\python26\lib\site-packages\matplotlib\__init__.py", line
    133, in<module>
    ? ? import sys, os, tempfile
    ? File "c:\python26\lib\tempfile.py", line 34, in<module>
    ? ? from random import Random as _Random
    ? File "C:\python\code\mycode\random.py", line 1, in<module>
    ? ? from RandomArray import standard_normal
    ? File "C:\python\code\mycode\RandomArray.py", line 1, in<module>
    ? ? import ranlib
    ImportError: No module named ranlib

    When I create a new directory, copy xoptimize.py there, and run, the
    program works. Can someone explain why other files are "interfering"
    in the first case? Thanks.

    You'd need to post a list of the files in the directory before we'd have any idea why this is happening.
    No he doesn't. We can get that from the traceback.


    Bekiavsky, there's a file called random.py in your folder. Python
    doesn't treat the standard library fila any differently than it does
    your own files. It searches the path for the first file called
    "random" that it sees and it imports that. Since it finds your file
    first, that's the one it imports. The failure you're seeing is
    actually in your code-you're trying to import a module that shouldn't
    exist.
    In
  • Diez B. Roggisch at Nov 13, 2010 at 2:15 pm

    Beliavsky <beliavsky at aol.com> writes:

    After installing numpy, scipy, and matplotlib for python 2.6 and
    running the code from http://www.scipy.org/Cookbook/OptimizationDemo1
    (stored as xoptimize.py) in a directory with other python codes, I got
    the error messages

    C:\python\code\mycode>python xoptimize.py
    Traceback (most recent call last):
    File "xoptimize.py", line 3, in <module>
    from pylab import *
    File "c:\python26\lib\site-packages\pylab.py", line 1, in <module>
    from matplotlib.pylab import *
    File "c:\python26\lib\site-packages\matplotlib\__init__.py", line
    133, in <module>
    import sys, os, tempfile
    File "c:\python26\lib\tempfile.py", line 34, in <module>
    from random import Random as _Random
    File "C:\python\code\mycode\random.py", line 1, in <module>
    from RandomArray import standard_normal
    File "C:\python\code\mycode\RandomArray.py", line 1, in <module>
    import ranlib
    ImportError: No module named ranlib

    When I create a new directory, copy xoptimize.py there, and run, the
    program works. Can someone explain why other files are "interfering"
    in the first case? Thanks.
    Because you probably have a file named the same way as some pyhon or
    matplotlib module, and that shadows the "real" one. Try copying more and
    more files into your new directory to find the culprit.

    Diez
  • Dave Angel at Nov 13, 2010 at 4:41 pm

    On 2:59 PM, Beliavsky wrote:
    After installing numpy, scipy, and matplotlib for python 2.6 and
    running the code from http://www.scipy.org/Cookbook/OptimizationDemo1
    (stored as xoptimize.py) in a directory with other python codes, I got
    the error messages

    C:\python\code\mycode>python xoptimize.py
    Traceback (most recent call last):
    File "xoptimize.py", line 3, in<module>
    from pylab import *
    File "c:\python26\lib\site-packages\pylab.py", line 1, in<module>
    from matplotlib.pylab import *
    File "c:\python26\lib\site-packages\matplotlib\__init__.py", line
    133, in<module>
    import sys, os, tempfile
    File "c:\python26\lib\tempfile.py", line 34, in<module>
    from random import Random as _Random
    File "C:\python\code\mycode\random.py", line 1, in<module>
    from RandomArray import standard_normal
    File "C:\python\code\mycode\RandomArray.py", line 1, in<module>
    import ranlib
    ImportError: No module named ranlib

    When I create a new directory, copy xoptimize.py there, and run, the
    program works. Can someone explain why other files are "interfering"
    in the first case? Thanks.
    You have a file random.py in your code directory, which is shadowing the
    system random library.

    DaveA
  • Terry Reedy at Nov 13, 2010 at 7:00 pm

    On 11/13/2010 11:41 AM, Dave Angel wrote:
    On 2:59 PM, Beliavsky wrote:
    After installing numpy, scipy, and matplotlib for python 2.6 and
    running the code from http://www.scipy.org/Cookbook/OptimizationDemo1
    (stored as xoptimize.py) in a directory with other python codes, I got
    the error messages

    C:\python\code\mycode>python xoptimize.py
    Traceback (most recent call last):
    File "xoptimize.py", line 3, in<module>
    Learn to read tracebacks. They are your debugging friend.
    from pylab import *
    xoptimize imports pylab
    File "c:\python26\lib\site-packages\pylab.py", line 1, in<module>
    from matplotlib.pylab import *
    pylab imports matplotlib
    File "c:\python26\lib\site-packages\matplotlib\__init__.py", line
    133, in<module>
    import sys, os, tempfile
    matplotlib imports tempfile (to get a plot destination)
    File "c:\python26\lib\tempfile.py", line 34, in<module>
    from random import Random as _Random
    tempfile import random (to make a 'random' tempfile name)
    File "C:\python\code\mycode\random.py", line 1, in<module>
    Look carefully at the above line. It should have been:
    File "C:\python26\lib\random.py ...

    Ignore the remaining error cascade.
    When I create a new directory, copy xoptimize.py there, and run, the
    program works. Can someone explain why other files are "interfering"
    in the first case? Thanks.
    You have a file random.py in your code directory, which is shadowing the
    system random library.
    As you can see in the traceback.

    --
    Terry Jan Reedy

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 13, '10 at 1:52p
activeNov 13, '10 at 7:00p
posts6
users6
websitepython.org

People

Translate

site design / logo © 2022 Grokbase