0

I have looked at other answers such as conda install future and others but none seem to solve this error. Everything was working till yesterday but today when I am trying to run my script I get this error.

I initially thought that I had multiple pandas packages from pip and conda so I uninstalled from both and then installed via conda again. But the error still persists.

I have installed python 3.6 as a separate environment in anaconda 2.

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'

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

EDIT 1

Following @EvgenyPogrebnyak's advice I created a new env named py36. I tried running the print statement python -c "import pandas as pd; print(pd.__version__)" statement from the home directory or infact any other directory it runs fine but when I run it from my project directory I get this particular error, which is weird.

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'
amitection
  • 2,696
  • 8
  • 25
  • 46
  • `import __builtin__` is not valid in python 3.6, you can see some discission [here](https://stackoverflow.com/questions/11181519/python-whats-the-difference-between-builtin-and-builtins). You seem to have some script in python 2.7 that you are trying to run under 3.6? this phrase seems suspicious: _I have installed python 3.6 as a separate environment in anaconda 2._ - what exactly did you do? my suggestion is to use [pipenv](https://github.com/pypa/pipenv) in new directory `pipenv --python 3.6` + `pipenv instpall pandas` – Evgeny Jun 09 '18 at 11:26
  • @EvgenyPogrebnyak I have been through that discussion previously but I am not sure what to do about it. Cause I am just importing pandas and internally probably it is using `__builtin__` . For installing python 3.6 I have followed [this](https://conda.io/docs/user-guide/tasks/manage-python.html#installing-a-different-version-of-python) guide. – amitection Jun 09 '18 at 11:41
  • It seems you have python 3 interpreter and pandas for version 2.7 for some reason. Did you activate new environment before instaling pandas and before running your script? – Evgeny Jun 09 '18 at 11:45
  • @EvgenyPogrebnyak yes I did. Infact I uninstalled it and then installed it again to be sure. – amitection Jun 09 '18 at 11:46
  • Please see the code in the answer, can you replicate it? – Evgeny Jun 09 '18 at 12:10

1 Answers1

0

I think code below should run. Exit enviornments is you are in one before running.

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

Does this run? You can install more libraries requred with conda install -n new1 <package> then try:

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

Similar result can be achieved with pipenv.

Evgeny
  • 4,173
  • 2
  • 19
  • 39
  • From what I understand it seems that you are creating a new environment and installing libraries in it. Well I tried your code but the problem still persists. – amitection Jun 09 '18 at 13:08
  • What is the effect (error message) of `python -c "import pandas as pd; print(pd.__version__)"`? – Evgeny Jun 09 '18 at 13:47
  • I get a weird result. I have updated the answer accordingly. – amitection Jun 09 '18 at 15:37
  • What is the list your dependecies? As requirements.txt or piplock file. Can you do provide the smallest code that allows to replicate your error? There is possibility there is package that may cause pandas to downgrade. – Evgeny Jun 09 '18 at 15:55