2

I tried to import matplotlib and pandas, like this (but separately):

import matplotlib.pyplot
import pandas

but each time there was an error. When i imported pandas, it said

Traceback (most recent call last):
  File "<pyshell#36>", line 1, in <module>
    import pandas
  File "C:\Users\bobby\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pandas\__init__.py", line 23, in <module>
    from pandas.compat.numpy import *
  File "C:\Users\bobby\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pandas\compat\__init__.py", line 439, in <module>
    from dateutil import parser as _date_parser
  File "C:\Users\bobby\AppData\Local\Programs\Python\Python35-32\lib\site-packages\dateutil\parser\__init__.py", line 2, in <module>
    from ._parser import parse, parser, parserinfo
  File "C:\Users\bobby\AppData\Local\Programs\Python\Python35-32\lib\site-packages\dateutil\parser\_parser.py", line 43, in <module>
    from six import binary_type, integer_types, text_type
ImportError: cannot import name 'binary_type'

so I went on command prompt (windows) and tried pip install --upgrade pandas and pip install binary_type, but neither of them worked.

When I imported matplotlib, it said

    Traceback (most recent call last):
  File "<pyshell#40>", line 1, in <module>
    import matplotlib.pyplot
  File "C:\Users\bobby\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\__init__.py", line 127, in <module>
    from . import cbook
  File "C:\Users\bobby\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\cbook\__init__.py", line 12, in <module>
    from six.moves import xrange, zip
ImportError: No module named 'six.moves'; 'six' is not a package

so like before I did pip install --upgrade six , pip install six, and pip install six.move, but none of these work.

What should I do so that both of these modules work?

B. Johnson
  • 45
  • 6
  • 2
    Note that a python error consists of more than one line. You may want to show the full traceback for each of the commands separately. – ImportanceOfBeingErnest Jul 20 '19 at 22:27
  • What's the console output returned when you run `where python` and `where pip` at the command line? They might be referring to different installations possibly. – jxramos Jul 21 '19 at 00:04
  • you may have two pythons installed and `pip` may install modules for other python. You can use `python -m pip install ...` to install in correct python. – furas Jul 21 '19 at 00:57
  • I tried `where python` and `where pip` and they led to `Python35-32/python.exe` and `Python35-32/Scripts/pip.exe`. – B. Johnson Jul 21 '19 at 12:30
  • I also tried `python -m pip install ...` but the same thing came up. It said that six was already installed to `Python35-32/lib/site-packages`, and `no matching distribution found for six.moves` – B. Johnson Jul 21 '19 at 13:52
  • I found out that there is a `pip.exe`, `pip3.3.exe`, and a `pip3.5.exe` in `Python35-32/Scripts`, but there is another `pip3.5.exe` in `Python35-32/Lib/site-packages/pip`, so maybe that is the problem. – B. Johnson Jul 21 '19 at 14:27
  • Do you have a file in your local directory named `six.py`? (or `six.pyc`) From your shell, try this: `import six; print(six.__file__)` – John Gordon Jul 21 '19 at 14:36
  • Do you have multiple installations of python? make sure to check your environment variable 'path' (Windows settings) and see that the correct python installation comes first. – FObersteiner Jul 21 '19 at 14:37
  • `six.__file__` gives me `Python35-32/six.py`. I'm pretty sure I only have one installation of python. – B. Johnson Jul 21 '19 at 14:46
  • `six.__file__` is `Python35-32/six.py`, not `Python35-32/lib/site-packages/six.py`? – John Gordon Jul 21 '19 at 16:15
  • I found the problem. It seems that there was another file, unrelated to the six module, named six.py, and when the program imported six, it took it from that file, instead of the real module. Once I renamed the file to something else, it imported the right file and worked. Thanks for the help. – B. Johnson Jul 21 '19 at 16:48
  • are you uing python 2 or python 3 ? use python 3 and work – Anshuman Jayaprakash Nov 26 '22 at 12:11

0 Answers0