0
from functools import reduce 

I'm using python 3.6.2, and this is the only code that shows the following error:

Traceback (most recent call last): File "D:\Pythons\oop.py", line 50, in <module> from functools import reduce ImportError: cannot import name 'reduce' Process returned 1 (0x1) execution time : 0.145 s 

I will find this problem because I made a mistake in another code,

from enum import Enum 

It reported the error:

Traceback (most recent call last): File "D:\Pythons\oop.py", line 50, in <module> from enum import Enum File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\enum.py", line 3, in <module> from functools import reduce ImportError: cannot import name 'reduce' 

So I just looked at the enum. Py source,Found in line 3

from functools import reduce 

Ladies and gentlemen, in centos7.2 installed python3.6.2 is completely out of any problems, but under the Windows 10 professional version installed, will appear these problems above, seems I installed out of the question, however, many times I've uninstalled, installed the many times repeatedly, still won't do, don't know without those documents, who can tell me how to through the command line in the Windows environment to install it?

5
  • so python can't import reduce from functools. I can't find a class/method named reduce neither in python 3. github.com/python/cpython/blob/3.6/Lib/functools.py - this was in python 2 available docs.python.org/2/library/functools.html#functools.reduce Commented Jul 27, 2017 at 11:02
  • That code works fine on python.org/shell which uses version3.6.0. maybe reinstall, or do a full install with all python packages? Commented Jul 27, 2017 at 14:57
  • I just installed 3.6.2 and I'm not able to replicate. reduce is even listed on the documentation page Commented Jul 27, 2017 at 14:58
  • 1
    Sounds like you named a file something you shouldn't. Commented Jul 28, 2017 at 2:27
  • To clarify the comment from @user2357112, I've run into this error when I've created a file named functools.py in a location higher up on the path than the intended import. Rename the file you created called functools.py. If this is not the case, then your installation is likely bad. Commented Jul 28, 2017 at 14:15

2 Answers 2

1

Python 3.6 should have reduce in functools. To debug your problem, try this:

import functools for obj in dir(functools): print(obj) 

I would expect an output similar to (tried it here: https://www.python.org/shell/):

MappingProxyType RLock WRAPPER_ASSIGNMENTS WRAPPER_UPDATES WeakKeyDictionary _CacheInfo _HashedSeq __all__ __builtins__ __cached__ __doc__ __file__ __loader__ recursive_repr __name__ __package__ __spec__ _c3_merge _c3_mro _compose_mro _convert _find_impl _ge_from_gt _ge_from_le _ge_from_lt _gt_from_ge _gt_from_le _gt_from_lt _le_from_ge _le_from_gt _le_from_lt _lru_cache_wrapper _lt_from_ge _lt_from_gt _lt_from_le _make_key cmp_to_key get_cache_token lru_cache namedtuple partial partialmethod recursive_repr reduce singledispatch total_ordering update_wrapper wraps 

My guess is more than reduce will be missing. In any case, it looks like an Uninstall than Reinstall is in order. You may have accidently edited the file or corrupted it in some way. Sometimes an IDE could take you to that function and it would be easy to edit it accidentally.

Sign up to request clarification or add additional context in comments.

1 Comment

builtins cached doc file loader name package spec functools I just showed that
0

Don't take care of those errors. Just try to use functools in your code :

import functools # Create a list of strings: stark stark = ['robb', 'sansa', 'arya', 'eddard', 'jon'] # Use reduce() to apply a lambda function over stark: result result = functools.reduce((lambda item1,item2:item1 + item2), stark) 

or like that :

# Import reduce from functools from functools import reduce # Create a list of strings: stark stark = ['robb', 'sansa', 'arya', 'eddard', 'jon'] # Use reduce() to apply a lambda function over stark: result result = reduce((lambda item1,item2:item1 + item2), stark) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.