Can't import sparkdl with spark-deep-learning-assembly-0.1.0-spark2.1.jar
See original GitHub issueFirst of all, thank you for a great library!
I tried to use sparkdl in PySpark, but couldn’t import sparkdl. Detailed procedure is as follows:
# make sparkdl jar
build/sbt assembly
# run pyspark with sparkdl
pyspark --master local[4] --jars target/scala-2.11/spark-deep-learning-assembly-0.1.0-spark2.1.jar
# import sparkdl
import sparkdl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sparkdl
After digging a few places, I found that it works if I deflate the jar file as follows.
cd target/scala-2.11
mkdir tmp
cp spark-deep-learning-assembly-0.1.0-spark2.1.jar tmp/
cd tmp
jar xf spark-deep-learning-assembly-0.1.0-spark2.1.jar
pyspark --jars spark-deep-learning-assembly-0.1.0-spark2.1.jar
import sparkdl
Using TensorFlow backend.
Edited-1 : The second method works only in the directory where the jar file is deflated.
Best wishes, HanCheol
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (3 by maintainers)
Top Results From Across the Web
Spark deep learning Import error - Stack Overflow
Its not a full fix, as i have yet to be able to import things from sparkdl in jupyter notebooks aswell, but!
Read more >Jeff Zhang - Apache
I experienced "ImportError: No module named sparkdl" exception while trying to use databricks' spark-deep-learning (sparkdl) in PySpark.
Read more >Not able to import sparkdl in jupyter notebook - Python技术博客
When I am running the below command pyspark --packages databricks:spark-deep-learning:1.5.0-spark2.4-s_2.11 I am able to import sparkdl in the spark shell.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After a few hours of googling/testing, I finally found a complete solution for my problem.
When I run pyspark in local mode, --packages option is enough to import sparkdl.
But it breaks when pyspark runs in yarn mode.
Interestingly, spark-submit runs a python program having the same import code without any problem.
Based on the information found here, https://issues.apache.org/jira/browse/SPARK-5185, I manually added paths to the downloaded jars into sys.path variable (which is equivalent to PYTHONPATH). And it started to work.
Based on the results of these try&error, it seems like pyspark in yarn mode doesn’t properly set PYTHONPATH for the jar files added by --packages option.
Best wishes, Hancheol
If you don’t need to change the code, the easiest way to start pyspark with the library would be
If you need to use the jar, it should work if you also add the jar to the PYTHONPATH environment variable before the pyspark command. e.g. for bash:
Hope that works!