Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
873 views
in Technique[技术] by (71.8m points)

python - AttributeError: module 'numpy' has no attribute '__version__'

I updated my computer today, and am getting the following error message when I attempt to import pandas:

import pandas as pd        
AttributeError: module 'numpy' has no attribute '__version__'

I have tried the suggestions from the following links:

  1. AttributeError: 'module' object has no attribute '__version__'
  2. AttributeError: 'module' object has no attribute '__version__'

I do not have any files names numpy.py other than the numpy package.

I am running anaconda2 within windows 10, and have created a python 3.5 virtual environment.

Following is the full error message:

Python 3.5.5 | packaged by conda-forge | (default, Apr  6 2018, 16:03:44) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:Usersj267156AppDataLocalContinuumanaconda2envssf35libsite-packagespandas\__init__.py", line 23, in <module>
    from pandas.compat.numpy import *
  File "C:Usersj267156AppDataLocalContinuumanaconda2envssf35libsite-packagespandascompat
umpy\__init__.py", line 10, in <module>
    _np_version = np.__version__
AttributeError: module 'numpy' has no attribute '__version__'

Edit: performing the following commands gives an error

import numpy
print(numpy.__file__)
AttributeError: module 'numpy' has no attribute '__file__'
print(numpy.version.version)
AttributeError: module 'numpy' has no attribute 'version'

Edit2: perfoming the following commands gives me the following errors:

import numpy as np
np.zeros(5)
#AttributeError: module 'numpy' has no attribute 'zeros'
vars(np).keys()
#dict_keys(['__name__', '__package__', '__spec__', '__loader__', '__doc__', '__path__'])

Edit3: the following commands result in the following output:

import numpy as np    
In [7]: np.__path__
    Out[7]: _NamespacePath(['C:\Users\j267156\AppData\Local\Continuum\anaconda2\envs\sf35\lib\site-packages\numpy'])

    In [8]: np.__loader__
    Out[8]: <_frozen_importlib_external._NamespaceLoader at 0x2033a3c8080>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this

In Jupyter notebook first uninstall the existing numpy by using !pip uninstall numpy.

Then install it !pip install numpy. Now restart the kernel(Python Notebook). It will work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...