ImportError: cannot import name add_newdocs

2019-04-06 00:23发布

I use Windows8.1 and python 2.7 and I installed the numpy1.8. However, whenever I wanna import numpy it shows the following error :ImportError: cannot import name add_newdocs.

>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\numpy\__init__.py", line 153, in <module>
    from . import add_newdocs
ImportError: cannot import name add_newdocs

I have checked with C:\Python27\Lib\site-packages\numpy the add_newdocs does exist.

Can somebody tell me how to fix it?

6条回答
太酷不给撩
2楼-- · 2019-04-06 00:42

I had a similar problem to this. First make sure that you can at least import numpy in the terminal python shell without the import error. If this is not the case, then it could be that a complete reinstall of numpy is necessary (or maybe as some other posts have said your pyc file for add_newdocs went "stale", needs to be deleted and will automatically be recreated and thus problem will be solved)

Or. The import does work in terminal and, (in my one experience with this bug) it was a problem of file names in the same folder. Moving the file that imported numpy out of that folder solved the issue.

Or its none of the above and in that case I'm out of ideas

查看更多
太酷不给撩
3楼-- · 2019-04-06 00:42

This should probably be a comment (reputation doesn't allow commenting yet):

I encountered the same error; in my case maybe because there were two python directories in the path (there's normal python and an anaconda python) - both have numpy. The former was added via

sys.path.insert(0,'/usr/local/lib/python2.7/dist-packages')

Replacing this with:

site.addsitedir('/usr/local/lib/python2.7/dist-packages')

solved the problem for some reason.

I can't reproduce the original "add_newdocs" error now, though. As written here there are issues with ...insert(0,..), but ..insert(1,..) also gives errors...

查看更多
走好不送
4楼-- · 2019-04-06 00:43

I had this problem after upgrading Ubuntu. I solved it by updating numpy:

sudo pip install numpy --upgrade
查看更多
甜甜的少女心
5楼-- · 2019-04-06 00:47

I am using Windows7 64-bit and was facing the same problem before. I solved it by updating numpy for Windows:

pip install numpy --upgrade

Thanks.

查看更多
地球回转人心会变
6楼-- · 2019-04-06 00:51
  • in where you save the python ...\Lib\site-packages

  • delete this folder "numpy" in the folder "site-packages"

  • then in the command line, under the path where you save the python.exe

    in my case: input "cd /d D:\anaconda" in the command line, press Enter

    and then input "pip install -U numpy" again, press Enter

  • after searching for 3 hours, finally find this way works for me, sincerely wish this could help you.

查看更多
我命由我不由天
7楼-- · 2019-04-06 00:55

just reinstall if your use anaconda conda install numpy I resolve it by doing that

查看更多
登录 后发表回答