Importing matplotlib correctly without pandas

Viewed 284

I am currently learning about matplotlib use in python, and I have found myself in a situation where I get an error:

Traceback (most recent call last):
  File "C:/Users/user/Desktop/Machine Learning/plt.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "C:\Python37\lib\site-packages\matplotlib\__init__.py", line 200, in <module>
    _check_versions()
  File "C:\Python37\lib\site-packages\matplotlib\__init__.py", line 194, in _check_versions
    module = importlib.import_module(modname)
  File "C:\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: The specified module could not be found.

I have installed my python to 64-bit and I used this website to install matplotlib (I installed matplotlib-3.1.0-cp37-cp37m-win_amd64.whl), also my current python version is 3.7.3, so I did all that and I ran my code where I get the error:

import matplotlib.pyplot as plt
plt.plot([1,2,3],[5,7,4])
plt.show()

To correct this I found in forums that for some people importing pandas worked so I tried that

import pandas as pan
import matplotlib.pyplot as plt
plt.plot([1,2,3],[5,7,4])
plt.show()

And it worked! So my question is why is that, how I can I fix it so I do not have to import pandas.

1 Answers

So the solution that works for me now and I am not sure why it even works, anyone who knows why can add some commment:

  1. Uninstalled matplotlib

  2. Installed Visual Studio 2019 and all the python tools

  3. Installed matplotlib once more using pip

Another solution would be to go for python 3.5 and matplotlib 3.0.3 which works smoothly.

Related