You are not logged in.

#1 2009-07-20 22:37:33

matthewbauer
Member
From: /usa/ks
Registered: 2009-07-20
Posts: 86

Errors from inside Python's own source files

When I try to run a Python script: python dbmakefakelib.py (it's for Dropbox) I get an error:

Traceback (most recent call last):
  File "dbmakefakelib.py", line 1, in <module>
    import commands, re, os, threading, time, sys
  File "/usr/local/lib/python2.6/threading.py", line 13, in <module>
    from functools import wraps
  File "/usr/local/lib/python2.6/functools.py", line 10, in <module>
    from _functools import partial, reduce
ImportError: cannot import name reduce

It seems to be coming from inside Python's own source files. Has anyone else I had this problem? I figure this out and Google's not helping much.

Last edited by matthewbauer (2009-07-21 22:10:36)


Libertarian Arch Linux User

Offline

#2 2009-08-25 17:59:38

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Errors from inside Python's own source files

Weird. Can you open up a python shell and manually type:

import commands, re, os, threading, time, sys

I'd also try reinstalling python.

Last edited by Profjim (2009-08-25 18:00:02)

Offline

#3 2009-10-27 13:44:40

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Errors from inside Python's own source files

Same problem here. Reduce is a function not a module, which would mean something is a bit off in the source.

UPDATE
I can confirm this is a problem. Generating a patch.

UPDATE

--- /usr/lib/python2.6/functools.py    2009-10-27 09:49:47.000000000 -0400
+++ functools.py    2009-10-27 09:49:31.000000000 -0400
@@ -7,7 +7,7 @@
 #   Copyright (C) 2006 Python Software Foundation.
 # See C source code for _functools credits/copyright
 
-from _functools import partial, reduce
+from _functools import partial
 
 # update_wrapper() and wraps() are tools to help write
 # wrapper functions that can handle naive introspection

Save the above patch to

functools.patch

then run the following command:

# patch -u /usr/lib/python2.6/functools.py functools.patch

Last edited by timetrap (2009-10-27 14:08:34)

Offline

#4 2009-10-27 13:54:41

keenerd
Package Maintainer (PM)
Registered: 2007-02-22
Posts: 647
Website

Re: Errors from inside Python's own source files

timetrap wrote:

Same problem here. Reduce is a function not a module, which would mean something is a bit off in the source.

I can confirm this is a problem. Generating a patch.

Please don't.  matthewbauer has an old version of python installed.  So do you.  I do not get that error on python 2.6.3-2.

By the way, you are allowed to import functions from modules.  I do it all the time, though functools.partial is much more useful that functools.reduce.

Offline

#5 2009-10-27 14:15:14

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Errors from inside Python's own source files

keenerd wrote:
timetrap wrote:

Same problem here. Reduce is a function not a module, which would mean something is a bit off in the source.

I can confirm this is a problem. Generating a patch.

Please don't.  matthewbauer has an old version of python installed.  So do you.  I do not get that error on python 2.6.3-2.

By the way, you are allowed to import functions from modules.  I do it all the time, though functools.partial is much more useful that functools.reduce.

Really? You can't do that with reduce. It's a built-in function. Try this:

import reduce

It fails with an ImportError. You can't do this in the manner that functools.py is trying. And I'm not running an older version of python (currently 2.6.3-2). This is an error.

But I think we need Allen to weigh in on this, he's the package maintainer.

UPDATE

Emailed Allen ...

Last edited by timetrap (2009-10-27 14:22:38)

Offline

#6 2009-10-27 14:33:38

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,385
Website

Re: Errors from inside Python's own source files

You are all using old versions of python (2.6.4-1 is out today), and quickly running that import line shows no errors. 

Edit:  in fact it appears to work with 2.6.3-2 (i686)....

Offline

#7 2009-10-27 14:41:51

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Errors from inside Python's own source files

Allan wrote:

You are all using old versions of python (2.6.4-1 is out today), and quickly running that import line shows no errors. 

Edit:  in fact it appears to work with 2.6.3-2 (i686)....

Damn you Allan! *Shakes fist at the sky*. You and your superior version numbers!

But seriously. The line in functools IS messed up. Right? You can't "import reduce" any more than you can "import print".

Offline

#8 2009-10-27 14:42:35

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Errors from inside Python's own source files

timetrap wrote:

But seriously. The line in functools IS messed up. Right? You can't "import reduce" any more than you can "import print".

No.  They are importing the 'reduce' function (or class.. etc.) from the _functools module.  You are assuming they are importing a 'reduce' module.

Last edited by rson451 (2009-10-27 14:47:00)


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#9 2009-10-27 14:45:22

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,385
Website

Re: Errors from inside Python's own source files

It is not "import reduce", it is:

from _functools import reduce

And you can import functions from within modules....

Offline

#10 2009-10-27 14:47:25

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Errors from inside Python's own source files

AH. I see. I think. But why, doesn't it work at all? Once I remove the reduce line, it works. Which leaves me a little confused.

Offline

#11 2009-10-27 14:51:22

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,385
Website

Re: Errors from inside Python's own source files

I have no idea why this is not working.  i686 or x86_64?

Offline

#12 2009-10-27 14:55:27

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Errors from inside Python's own source files

i686.

What I am understanding is this:

the module functools can be addressed internally via _functools, thus allowing an importing of functions from within itself. While there is a partial function there is no reduce function declared inside functools. So I left with a little confusion. Why would reduce even need to be imported if reduce is a built-in function?

I did find this bug report: http://bugs.python.org/issue1739906 But I'm still not sure what reduce is actually doing, in my functools.

Last edited by timetrap (2009-10-27 15:02:56)

Offline

#13 2009-10-27 15:03:37

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: Errors from inside Python's own source files

In python 3.x the builtin reduce() was removed.

python docs wrote:

Removed reduce(). Use functools.reduce()  if you really need it; however, 99 percent of the time an explicit for loop is more readable.

This change have been backported to 2.6 by doing this:

python docs wrote:

The addition of functools.reduce()  as a synonym for the built-in reduce()  function.


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#14 2009-10-27 15:06:52

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Errors from inside Python's own source files

If you're still running 2.6.3-2 please try this. I want to make sure I'm not crazy.

>>> import functools
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/functools.py", line 10, in <module>
    from _functools import partial, reduce
ImportError: cannot import name reduce

Offline

#15 2009-10-27 15:09:35

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,385
Website

Re: Errors from inside Python's own source files

> python
Python 2.6.3 (r263:75183, Oct  4 2009, 11:40:05) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import functools
>>>

All looks good to me with 2.6.3-2

Offline

#16 2009-10-27 15:11:51

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Errors from inside Python's own source files

So ... what happened? I installed python after a clean install of arch (on 10-24-2009).

pacman -Ql | grep functools
python /usr/lib/python2.6/functools.py
python /usr/lib/python2.6/functools.pyc
python /usr/lib/python2.6/functools.pyo
python /usr/lib/python2.6/lib-dynload/_functools.so
python /usr/lib/python2.6/test/test_functools.py
python /usr/lib/python2.6/test/test_functools.pyc
python /usr/lib/python2.6/test/test_functools.pyo

My current mirror is http://distro.ibiblio.org/pub/linux/dis … po/os/i686 ...

I also just ran

pacman -Sf python
# same error as above, reinstalled 2.6.3-2
pacman -Scc
pacman -Sf python
# same error as above, reinstalled 2.6.3-2
# I swithced mirrors to rit.edu
pacman -Syu
# upgraded python to 2.6.4-1
# same error.

Last edited by timetrap (2009-10-27 15:28:28)

Offline

#17 2009-10-27 15:30:15

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Errors from inside Python's own source files

So I've upgraded to python 2.6.4-1, and get the same error. Just to be on the safe side, I'll reboot.

Python 2.6.4 (r264:75706, Oct 27 2009, 06:16:59) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import functools
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/functools.py", line 10, in <module>
    from _functools import partial, reduce
ImportError: cannot import name reduce

Following a reboot, it works. Strange. Maybe something was locked? I'm not running anything in the background ...

Last edited by timetrap (2009-10-27 15:35:25)

Offline

#18 2009-10-27 15:58:43

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Errors from inside Python's own source files

Okay, I've recreated the problem, its a bit weird. All of the following commands are in the same terminal:

Python 2.6.4 (r264:75706, Oct 27 2009, 06:16:59) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import threading
>>> import functools
>>> import _functools
>>>

Running dbmakefakelib.py (which is linked from the archwiki), and makes all kind of badness happen.

.dropbox-dist/ python dbmakefakelib.py
Traceback (most recent call last):
  File "dbmakefakelib.py", line 2, in <module>
    import commands, re, os, threading, time, sys 
  File "/usr/lib/python2.6/threading.py", line 13, in <module>
    from functools import wraps
  File "/usr/lib/python2.6/functools.py", line 10, in <module>
    from _functools import partial, reduce
ImportError: cannot import name reduce
.dropbox-dist/ python
Python 2.6.4 (r264:75706, Oct 27 2009, 06:16:59) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import functools
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/functools.py", line 10, in <module>
    from _functools import partial, reduce
ImportError: cannot import name reduce
>>> import _functools
>>> import threading
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/threading.py", line 13, in <module>
    from functools import wraps
  File "/usr/lib/python2.6/functools.py", line 10, in <module>
    from _functools import partial, reduce
ImportError: cannot import name reduce
>>>

Offline

#19 2010-03-05 19:05:35

sirscott
Member
Registered: 2010-03-05
Posts: 3

Re: Errors from inside Python's own source files

I'm having the same problem running the python files for Dropbox.  Was a solution ever found?  I'm unable to get Dropbox to actually work for me and I'm wondering if it's somehow related to this python issue.

Offline

#20 2010-03-05 19:31:15

sirscott
Member
Registered: 2010-03-05
Posts: 3

Re: Errors from inside Python's own source files

If you notice in the .dropbox-dist/ directory, they have their own version of _functools.so.  If I copy the real one into that dir (cp /usr/lib/python2.6/lib-dynload/_functools.so ~/.dropbox-dist/), then the python script will at least execute, but I don't believe that it's executing correctly because it does not spew out the info mentioned on the Dropbox Wiki (http://wiki.dropbox.com/TipsAndTricks/T … nuxInstall).

So that leads me to think that for some reason it's the provided _functools.so file that is the problem.

Offline

Board footer

Powered by FluxBB