1

I am trying to import Numpy

import numpy as np

but I am getting this error:

AttributeError: module 'linecache' has no attribute 'checkcache'

Full trace:

Traceback (most recent call last):

  File "C:/Users/z1885/Desktop/鸡行为分析/codepy/ML/KNN.py", line 1, in <module>
    import numpy as np

  File "C:\Users\z1885\Desktop\bouk\venv\lib\site-packages\numpy\__init__.py", line 145, in <module>
    from . import lib

  File "C:\Users\z1885\Desktop\bouk\venv\lib\site-packages\numpy\lib\__init__.py", line 24, in <module>
    from .npyio import *

  File "C:\Users\z1885\Desktop\bouk\venv\lib\site-packages\numpy\lib\npyio.py", line 14, in <module>
    from ._datasource import DataSource

  File "C:\Users\z1885\Desktop\bouk\venv\lib\site-packages\numpy\lib\_datasource.py", line 41, in <module>
    import shutil

  File "C:\Users\z1885\Desktop\bouk\venv\lib\shutil.py", line 16, in <module>
    import bz2

  File "C:\Users\z1885\AppData\Local\Programs\Python\Python35\Lib\bz2.py", line 18, in <module>
    from threading import RLock

  File "C:\Users\z1885\AppData\Local\Programs\Python\Python35\Lib\threading.py", line 7, in <module>
    from traceback import format_exc as _format_exc

  File "C:\Users\z1885\AppData\Local\Programs\Python\Python35\Lib\traceback.py", line 5, in <module>
    import linecache

  File "C:\Users\z1885\Desktop\bouk\venv\lib\linecache.py", line 11, in <module>
    import tokenize

  File "C:\Users\z1885\Desktop\bouk\venv\lib\tokenize.py", line 34, in <module>
    from token import *

  File "C:\Users\z1885\Desktop\鸡行为分析\codepy\token.py", line 5, in <module>
    import request as request

  File "C:\Users\z1885\Desktop\bouk\venv\lib\site-packages\request\__init__.py", line 2, in <module>
    from get import GET

  File "C:\Users\z1885\Desktop\bouk\venv\lib\site-packages\get\__init__.py", line 3, in <module>
    from query_string import query_string

  File "C:\Users\z1885\Desktop\bouk\venv\lib\site-packages\query_string\__init__.py", line 18, in <module>
    @public.add

  File "C:\Users\z1885\Desktop\bouk\venv\lib\site-packages\public\__init__.py", line 65, in add
    return _add(_caller_modules()[1], objects)

  File "C:\Users\z1885\Desktop\bouk\venv\lib\site-packages\public\__init__.py", line 12, in _caller_modules
    frames = inspect.getouterframes(inspect.currentframe())

  File "C:\Users\z1885\AppData\Local\Programs\Python\Python35\Lib\inspect.py", line 1441, in getouterframes
    frameinfo = (frame,) + getframeinfo(frame, context)

  File "C:\Users\z1885\AppData\Local\Programs\Python\Python35\Lib\inspect.py", line 1414, in getframeinfo
    lines, lnum = findsource(frame)

  File "C:\Users\z1885\AppData\Local\Programs\Python\Python35\Lib\inspect.py", line 747, in findsource
    linecache.checkcache(file)
AttributeError: module 'linecache' has no attribute 'checkcache'
5
  • Can you update your question with the full traceback? Commented Mar 30, 2019 at 5:56
  • When I create a new project in pycharm and run the same code, it is solved. Commented Mar 30, 2019 at 6:32
  • Please check more closely & tag wisely: it is apparent that the error is about numpy, not about machine-learning of scikit-learn (tags edited). Commented Mar 30, 2019 at 10:52
  • 2
    The traceback says you named one of your files token.py. The standard library has dibs on the token module name. Using it for your own module breaks the standard library. (It's annoying, but you have to make sure you don't accidentally pick module names the standard library is already using.) Commented Mar 30, 2019 at 10:59
  • 1
    (Also I would strongly recommend using the requests module instead of this request thing you have installed.) Commented Mar 30, 2019 at 11:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.