Pycharm: “unresolved reference” error on the IDE when opening a working project

前端 未结 7 1852
日久生厌
日久生厌 2020-12-02 18:15

Intro

I have a Python project on a git repository. Everything works ok for most of the team members, we can sync the code and edit it without any pr

7条回答
  •  情歌与酒
    2020-12-02 18:49

    I faced similar issue with pyspark ( spark 2.1 ) & luigi.

    Failed tries:

    1. Setting PYTHONPATH environment variable
    2. Invalidate cache & restart pycharm
    3. Mark directory as Source Root


    Unresolved reference pyspark could be fixed by adding the spark's python directory as Content Root in the project, but running the project as luigi task gave the same error.

    Successfull steps

    • Create an empty __init__.py file in the project
    • Include following lines of code at the top of script

      ...
      import sys
      
      sys.path.append("/path/to/spark/python")
      
      sys.path.append("/path/to/spark/python/lib")
      
      ...
      // import pyspark files after above mentioned lines
      

    and the Unresolved reference error issue was fixed both in pycharm & luigi task.

提交回复
热议问题