PyCharm cannot find module from pip install

Viewed 175

I installed the module with the command: pip install matplotlib. However, PyCharm does not find the module I installed.

# importing the required module
import matplotlib.pyplot as plt

# x axis values
x = [1,2,3]
# corresponding y axis values
y = [2,4,1]

# plotting the points
plt.plot(x, y)

# naming the x axis
plt.xlabel('x - axis')
# naming the y axis
plt.ylabel('y - axis')

# giving a title to my graph
plt.title('My first graph!')

# function to show the plot
plt.show()

Error

4 Answers

The problem is that you install the matplotlib globally instead of in your current virtual environment. There are 2 ways to fix this:

  1. Activate your virtual environment in your command prompt first, then run the pip install command.
  2. Manage your packages via PyCharm package manager. Make sure that you set up the interpreter correctly.

I usually go with option 2 since it's easier that way.

I saw your attached image. I think the matplotlib is getting installed on the system python version but not on the python version installed on the Pycharm.

To install the matplotlib on the pycharm's python version you have to open Pycharm terminal and run the pip install matplotlib

I have a pretty good solution. Pycharm can't find the module so we will send the module to Pycharm[Default it save inC:\Users\"user name"\AppData\Local\Programs\Python\Python310\Lib\site-packages ]. We use pip config set global.target C:\Users\"user name"\PycharmProjects\pythonProject\venv\Lib\site-packages. I tried and succeeded. There may be a few other minor errors but remember just give pycharm the module's link.[sorry for my english]

first thing first you need to restart your idle to apply the package changes. second thing second you made an environment and you are running your project from it to fix it ether install matplotlib in environment that you created using venv or stop using the venv so your idle can access to main python files installed on your c drive if you are a little bit search for venv python in YouTube you'll get what I say

Related