1
import random
import matplotlib.pyplot as plt

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

freq = {c: random.randint(1, 100) for c in alphabet if random.randint(1, 10) > 2}
print(len(freq))
print(freq)

plt.bar(range(len(freq)), freq.values(), align='center')
plt.xticks(range(len(freq)), freq.keys())
plt.show()

I received a code which uses matplotlib, I already installed it like here in console (in Git Bash) and searched for matplotlib under settings - modules, but found just two other and installed them (aliasimports/live coding in python). I still become this error:

ModuleNotFoundError: No module named 'matplotlib'

2 Answers2

0

In Pycharm File -> View -> Tools Windows -> Python packages It will list all installed packages, search for Matplotlib and install it.

If you are running in terminal:

python -m pip install matplotlib

If on unix: locate your python, which python

python_path/bin/python -m pip install matplotlib

If you are using python2, without pip. Install it

wget https://bootstrap.pypa.io/get-pip.py

After saving above file, run

python get-pip.py

Now run pip install command.

If your script is using shebang, do include this line at top of your file

#!/path/to/your/path/binary
Ahmed Contrib
  • 646
  • 4
  • 5
  • The first sentence already helped me, thanks! A little edited path: "Pycharm -> View -> Tool Windows -> Python packages: It will list all installed packages, search for Matplotlib and install it" – Mihail Savvateev Jul 05 '21 at 15:23
0

before using any library in python you need to install it. for installation there are different methods(depend on OS) but simple way is PIP INSTALL PKG_NAME

Study only
  • 37
  • 6