Search code examples
pythonintellij-idea

Setting python interpreter in intellij in a multi language (scala/java/python) module


As shown in the following screenshot the python 2.7.2 sdk is configured

enter image description here

Also:

  • the python facet was added to module "spark-parent"
  • the "python" directory was added as a source root

But as you can see all of the standard python imports are failing. Note that the custom spark python ('pyspark') classses ARE resolved.enter image description here

In response to the answer from Dwight Brown: changing the Project SDK away from java to python does not work in this mixed project: see screenshot below

enter image description here


Solution

  • I have the same problem.

    After some tries I found this solution

    1. create a just empty module named java-dep-python etc then add it to project

      <module relativePaths="false" type="JAVA_MODULE" version="4">
        <component name="NewModuleRootManager" inherit-compiler-output="true">
          <orderEntry type="jdk" jdkName="Python 2.7" jdkType="Python SDK" />
          <orderEntry type="sourceFolder" forTests="false" />
        </component>
      </module>
      
    2. change all your mixed modules to add this new empty module as dependency

      <module relativePaths="true" type="JAVA_MODULE" version="4">
        <component name="FacetManager">
          <facet type="Python" name="Python">
            <configuration sdkName="Python 2.7" />
          </facet>
        </component>
        <component name="NewModuleRootManager" inherit-compiler-output="true">
          ... ...
          <orderEntry type="inheritedJdk" />
          <orderEntry type="module" module-name="java-dep-python" scope="PROVIDED" />
          ... ...
        </component>
      </module>
      

    Note that the PROVIDED keyword do help that this module is not required by any artifacts

    It works for me, now that standard python imports are good.

    IDEA 14.0.3 build #IU-139.1117