Friday, November 18, 2016

No module named pyspark in PyCharm when it imports normal from python prompt

It complains compile error for command `import pyspark` saying that 'No module named pyspark' in PyCharm provided spark is not installed by `pip install`, whereas it could be imported correctly from python prompt.

Solution:
Find the path for 'SPARK_HOME/python/lib/py4j-0.*.*-src.zip:$SPARK_HOME/python/lib/pyspark.zip'. In PyCharm, open Preferences window, search for 'Project Structure' pane, at the right side, there's a button named 'Add Content Root', add the above two *.zip files here and click OK. Then everything works fine as expected.



4 comments:

  1. It really works. Thanks for this article.

    ReplyDelete
  2. Awesomely good and working for me now

    ReplyDelete
  3. **“No module named PySpark in PyCharm when it imports normally from Python prompt”** explains a common environment issue where PySpark works correctly in the normal Python/Anaconda prompt but PyCharm shows `ModuleNotFoundError: No module named 'pyspark'`. This usually happens because **PyCharm is using a different Python interpreter or virtual environment** from the one where PySpark is installed. PySpark Course.The solution is to check PyCharm’s **Project Interpreter**, select the same Python/Conda environment used in the Python prompt, and verify that PySpark is installed in that environment. This is important for **Data Analytics and Big Data projects**, because the correct Python environment is required to run Spark programs successfully.

    ReplyDelete