How do I get IntelliJ to recognize common Python modules?

Toddarooski picture Toddarooski · May 23, 2011 · Viewed 104.1k times · Source

I'm using IntelliJ 10 IDEA Ultimate Edition.

I've created a new file Test.py, and IntelliJ has correctly switched to Python parsing mode. (I can confirm this by typing "d", it pops up "def" as a suggestion, and hitting tab correctly gives me "def :")

However, when I try this code...

import os

cwd = os.getcw <Ctrl-space>

Two things happen....

  1. I get a squggly underline underneath os and hovering over it gives me a "Unresolved reference 'os'" message
  2. I get no suggestions hitting Ctrl-space above, when I'm expecting to see "getcwd".

I'm assuming that this must be a result of my not configuring IntelliJ properly in order to handle python modules, but I have no idea what it is I'm missing.

Any IntelliJ/Python users able to help me out?

Answer

db42 picture db42 · Jul 21, 2012

Just create and add Python SDK

File -> Project Structure -> Project -> Project SDK -> new

and select the installation path of your Python interpreter (for example, C:\Python26 in windows and /usr/bin/python2.7 in Linux) as the home path.

Related discussion: http://devnet.jetbrains.net/thread/286883