Python Forum

Full Version: can not import name invalidate_caches
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi,
I use Python 2.7. I have an Import Error: can not import name invalidate_caches. What should I do? 

from importlib import invalidate_caches
https://docs.python.org/2.7/library/importlib.html

(Apr-30-2017, 04:37 PM)Bani Wrote: [ -> ]Hi,
I use Python 2.7. ... What should I do? 

Upgrade to a version of python which has that module?
I have the same error in python3.5.
Mind showing the full traceback?  I'm on 3.6, so I can't replicate exactly what you're on, but it seems to work on my end.

D:\Projects\playground>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib import invalidate_caches
>>> invalidate_caches()
>>> help(invalidate_caches)
Help on function invalidate_caches in module importlib:

invalidate_caches()
   Call the invalidate_caches() method on all meta path finders stored in
   sys.meta_path (where implemented).

>>>
No problem with Python 3.5.2

Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib import invalidate_caches
>>> 
Is this issue raised by you?
I get this with Python 2

~ ❯❯❯ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib import invalidate_caches
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name invalidate_caches
(May-01-2017, 08:36 AM)wavic Wrote: [ -> ]I get this with Python 2
Did you read post#2 by nilamo?

Also OP is now running python 3.5. (as per the screenshot he provided - Interpreter settings)
You didn't happen to name one of your files "importlib.py", did you?

The error is saying that the file is found, but that the function doesn't exist within it. Since importlib is part of the standard library, maybe the file's being shadowed somewhere?
Pages: 1 2