How do I get IntelliJ to recognize common Python modules?

前端 未结 12 1297
甜味超标
甜味超标 2020-12-04 09:09

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 t

相关标签:
12条回答
  • 2020-12-04 09:37

    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

    0 讨论(0)
  • 2020-12-04 09:38

    If your Python SDK is properly configured and you are still facing the problem that builtins are not recognized, try this:

    File -> Invalidate Caches/Restart
    
    0 讨论(0)
  • 2020-12-04 09:40

    Use a Requirements File (see link to JetBrains documentation)

    In my case I needed arrow. So, I added

    arrow==0.7.0

    to my projects requirements.txt

    Then Intellij prompted me to add the library the first time that I wrote import arrow in a Python script

    0 讨论(0)
  • 2020-12-04 09:42

    Even my Intellisense in Pycharm was not working for modules like time Problem in my system was no Interpreter was selected Go to File --> Settings... (Ctrl+Alt+S) Open Project Interpreter

    Project Interpreter In my case was selected. I selected the available python interpreter. If not available you can add a new interpreter.

    0 讨论(0)
  • 2020-12-04 09:45

    I got it to work after I unchecked the following options in the Run/Debug Configurations for main.py

    Add content roots to PYTHONPATH

    Add source roots to PYTHONPATH

    This is after I had invalidated the cache and restarted.

    0 讨论(0)
  • 2020-12-04 09:46

    (solved my problem) File -> Project structures -> Modules -> Add (small plus sign) -> Import Module -> Add the path contains the files (e.g. src/mymodule) -> Create Module from existing sources -> Next -> next -> Finish. You should see a file with .iml in the directory where you cannot imoport; that should do the trick

    0 讨论(0)
提交回复
热议问题