Python 2.7.3 tempfile.py, ln34, from random import Random as _Random

D

dbv

In Python 2.7.3, at ln34 the source file tempfile.py states:

from random import Random as _Random

But, Random is a Class.

The project imports werkzeug and using PyInstaller, the Traceback is:

Traceback (most recent call last):
File "<string>", line 9, in <module>
File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 404, in load_module
module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
File "xserver.pyx", line 18, in init xserver (//home//ubuntu//Programs//myproject//myproject_pyx/xserver.c:2481)
File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module
exec(bytecode, module.__dict__)
File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/werkzeug.wrappers", line 26, in <module>
File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module
exec(bytecode, module.__dict__)
File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/werkzeug.http", line 25, in <module>
File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module
exec(bytecode, module.__dict__)
File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/urllib2", line 94, in <module>
File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module
exec(bytecode, module.__dict__)
File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/httplib", line 79, in <module>
File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module
exec(bytecode, module.__dict__)
File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/mimetools", line 6, in <module>
File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module
exec(bytecode, module.__dict__)
File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/tempfile", line 34, in <module>
ImportError: cannot import name Random

Is this a bug? Or, is there some workaround available? Thx.
 
P

Peter Otten

dbv said:
In Python 2.7.3, at ln34 the source file tempfile.py states:

from random import Random as _Random

But, Random is a Class.

This is not a problem. You can import arbitrary objects from a module.

The project imports werkzeug and using PyInstaller, the Traceback is:

Traceback (most recent call last):
File "<string>", line 9, in <module>
File
[...]
line 268, in load_module
exec(bytecode, module.__dict__)
File
"//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-
PYZ.pyz/tempfile",
line 34, in <module>
ImportError: cannot import name Random

Is this a bug? Or, is there some workaround available? Thx.

I don't know about PyInstaller or werkzeug, but the most likely cause is
that you shaded the standard library's random module with your own random.py
which doesn't contain an object named "Random". Here's a demonostration:

Normal behaviour:

$ python -c 'from random import Random as _Random'

Now add an empty random.py:

$ touch random.py
$ python -c 'from random import Random as _Random'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name Random

Back to normal:

$ rm random.pyc random.py
$ python -c 'from random import Random as _Random'
 
D

Dave Angel

In Python 2.7.3, at ln34 the source file tempfile.py states:

from random import Random as _Random

But, Random is a Class.

Have you just tried the following:

import random
print dir(random.random)
print random.__file__

I suspect you have another random.py (or equivalent) in your sys.path
 
D

dbv

I have a number of .py source files and one source file has an "import random" and another has "import werkzeug".

The project works perfectly in the Python interpreter.

Problem appears when using PyInstaller.

How do get out of jail?
 
D

dbv

I have a number of .py source files and one source file has an "import random" and another has "import werkzeug".

The project works perfectly in the Python interpreter.

Problem appears when using PyInstaller.

How do get out of jail?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top