7

I am working on learning how to use pandas in ipython notebook:

import pandas as pd

But I get the following error:

AttributeError                            Traceback (most recent call last)
<ipython-input-17-c7ecb2b0a99d> in <module>()
----> 1 from pandas  import *

D:\Anaconda\lib\site-packages\pandas\__init__.py in <module>()
 20 
 21 # numpy compat
---> 22 from pandas.compat.numpy import *
 23 
 24 try:

D:\Anaconda\lib\site-packages\pandas\compat\numpy\__init__.py in <module>()
  8 
  9 # numpy versioning
---> 10 _np_version = np.version.short_version
 11 _nlv = LooseVersion(_np_version)
 12 _np_version_under1p8 = _nlv < '1.8'

AttributeError: module 'numpy' has no attribute 'version'

I have no idea about how to fix it, what is the problem?My python's version is 3.6

5
  • 1
    strange. Do you have a file named numpy.py floating around somewhere? Commented Mar 26, 2017 at 3:38
  • Yes,the path is "D:\Anaconda\lib\site-packages\partd\numpy.py Commented Mar 26, 2017 at 3:43
  • 1
    You made that file? Why? And why put it in site-packages? Commented Mar 26, 2017 at 3:44
  • You mean I should remove this file from the site-packages? Where should I locate this file? Commented Mar 26, 2017 at 5:57
  • 3
    Did you add that file? You shouldn't be messing with that folder unless you know what you are doing. It is part of the PYTHONPATH that gets checked when you import something. What is likely happening is that when some other module use import numpy numpy will now be that file but it should be referring to the numpy package. Commented Mar 26, 2017 at 5:59

1 Answer 1

3

Numpy has dependencies and Anaconda has a history of getting them wrong leading to numpy failing to initialize properly. The AttributeError is most likely caused by numpy initialization failure. This error usually happens when updating numpy or other dependencies that change numpy versions via conda (that's why you can get numpy failing after updating Pandas...)

Example of such failure: https://github.com/ipython/ipyparallel/issues/326

The solution that always works for me is updating to a known working version of numpy. Currently, for me on Windows 10 x64, it is 1.15.1.

Please note it is a problem with Anaconda dependencies rather than numpy itself. Can't provide more specific guidance without details like OS, package versions, etc.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.