Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 875
WestCoastProjects Avatar asked Jan 10 '23 07:01

WestCoastProjects


2 Answers

almost there, the only thing you were missing is to set the Python interpreter for the actual facet. I had to restart Intellij in order for things to actually apply.

enter image description here

like image 194
Daniel Langdon Avatar answered Jan 16 '23 20:01

Daniel Langdon


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

like image 45
William Leung Avatar answered Jan 16 '23 20:01

William Leung