ModuleNotFoundError:没有名为' __ builtin __'在康达

时间:2018-06-09 10:40:35

标签: python pandas anaconda conda

我已经查看了其他答案,例如conda install future和其他答案,但似乎没有解决此错误。一切都工作到昨天,但今天当我试图运行我的脚本时,我得到了这个错误。

我最初认为我有来自pip和conda的多个pandas软件包,所以我从两者中卸载然后再通过conda安装。但错误仍然存​​在。

我已经在anaconda 2中安装了python 3.6作为一个单独的环境。

Traceback (most recent call last):
  File "/Users/amit/anaconda2/envs/python36/lib/python3.6/site-packages/pandas/compat/__init__.py", line 49, in <module>
    import __builtin__ as builtins
ModuleNotFoundError: No module named '__builtin__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 18, in <module>
    from nameserver import NameServer
  File "/Users/amit/Work/ml/marl/nameserver.py", line 4, in <module>
    import pandas as pd
  File "/Users/amit/anaconda2/envs/python36/lib/python3.6/site-packages/pandas/__init__.py", line 23, in <module>
    from pandas.compat.numpy import *
  File "/Users/amit/anaconda2/envs/python36/lib/python3.6/site-packages/pandas/compat/__init__.py", line 62, in <module>
    import http.client as httplib
ModuleNotFoundError: No module named 'http.client'

=============

编辑1

按照@ EvgenyPogrebnyak的建议,我创建了一个名为py36的新环境。我尝试从主目录运行print语句python -c "import pandas as pd; print(pd.__version__)"语句或者其他任何运行良好的目录,但是当我从项目目录运行它时,我得到了这个特殊的错误,这很奇怪。

amit:~ $source activate py36
(py36) amit:~ $python -c "import pandas as pd; print(pd.__version__)"
0.23.0
(py36) amit:~ $cd Work/ml/marl/
(py36) amit:~/Work/ml/marl $python -c "import pandas as pd; print(pd.__version__)"
Traceback (most recent call last):
  File "/Users/amit/anaconda2/envs/py36/lib/python3.6/site-packages/pandas/compat/__init__.py", line 49, in <module>
    import __builtin__ as builtins
ModuleNotFoundError: No module named '__builtin__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/amit/anaconda2/envs/py36/lib/python3.6/site-packages/pandas/__init__.py", line 23, in <module>
    from pandas.compat.numpy import *
  File "/Users/amit/anaconda2/envs/py36/lib/python3.6/site-packages/pandas/compat/__init__.py", line 62, in <module>
    import http.client as httplib
ModuleNotFoundError: No module named 'http.client'

1 个答案:

答案 0 :(得分:0)

我认为下面的代码应该运行。退出环境是你在跑步之前。

conda create -n new1 python=3.6 pandas
source activate new1
python --version
# expected:
# Python 3.6.0 :: Anaconda 4.3.0 (32-bit)
python -c "import pandas as pd; print(pd.__version__)"
# expected '0.22.0',but more importantly this shows pandas in imported

这会运行吗?您可以安装更多需要conda install -n new1 <package>的库,然后尝试:

python /Users/amit/Work/ml/marl/nameserver.py

使用pipenv可以获得类似的结果。