8

My IntelliJ version is 15.0.3, and have python plugin installed.

And when I open a python file in IntelliJ it's like below enter image description here

Situation here is like below:

  1. when I import these flagged modules in terminal, everything works fine.
  2. running this python file in IntelliJ, is also fine

It's only the red underlying warning annoying me.

I tried this one, this one and this one, but none works for me.

Could anyone please tell me how to get rid of it? Thanks a lot.

Community
  • 1
  • 1
keypoint
  • 2,268
  • 4
  • 31
  • 59

2 Answers2

9

You have to add the site-packages path of your interpreter.

For that you have to:

  1. go to Project Structure
  2. choose Global Libraries
  3. choose your Python interpreter
  4. press + at the upper left corner
  5. choose the site-package path of your interpreter
  6. choose "Classes"

also add your python interpreter root directory in the same way.

Vasco
  • 395
  • 2
  • 13
  • I'm trying to use mysql.connector and experiencing the same problem as the asker, but following this did not solve it for me (site-packages was already in library list). Any other ideas? – Twisted on STRIKE at1687989253 Jun 27 '22 at 23:45
  • also didn't work for me, however use `python3 -m site` to find your site-package path – lobi Apr 14 '23 at 19:24
0

I have similar problems: cannot import manually installed module. I try to add classpath in Mac environment parameters and intellij SDKs, but it doesn't work. My final solution is to add the classpath of the module to Run/Debug Configurations:

Open Run/Debug Configurations and select your unittest class:

Run --> Edit Configurations...

Add your module's classpath to Environment variables: enter image description here

Pingjiang Li
  • 727
  • 1
  • 12
  • 27