I am trying to export a Bokeh plot to png using their export_png
method from bokeh.io
, however, I am running into an RuntimeError, stating PhantomJS is not present in PATH or BOKEH_PHANTOMJS_PATH.
I am using the Jupyter notebook environment with Python 3.7.3.
I've tried conda install -c conda-forge phantomjs
and conda install -c conda-forge selenium
(as well as conda install phantomjs
and conda install selenium
), but to no avail.
Any help would be appreciated - I am happy to provide more detail!
Here is a segment of the exception below:
//anaconda3/lib/python3.7/site-packages/bokeh/io/webdriver.py in create_phantomjs_webdriver()
73 '("conda install -c bokeh selenium" or "pip install selenium")')
74
---> 75 phantomjs_path = detect_phantomjs()
76 return webdriver.PhantomJS(executable_path=phantomjs_path, service_log_path=devnull)
77
//anaconda3/lib/python3.7/site-packages/bokeh/util/dependencies.py in detect_phantomjs(version)
124 except OSError:
125 raise RuntimeError('PhantomJS is not present in PATH or BOKEH_PHANTOMJS_PATH. Try "conda install phantomjs" or \
--> 126 "npm install -g phantomjs-prebuilt"')
127
128 return phantomjs_path
RuntimeError: PhantomJS is not present in PATH or BOKEH_PHANTOMJS_PATH. Try "conda install phantomjs" or "npm install -g phantomjs-prebuilt"
Ok so I figured out a way to handle this issue...
FIRST: try this:
conda install -c conda-forge phantomjs
If that doesn't work, then do the following:
I verified that I had the phantomjs
library in my anaconda3 environment (as below).
/anaconda3/lib/python3.7/site-packages/phantomjs
The issue is, my Jupyter notebook was working in a environment that was not anaconda3.
So what I did is:
1) conda install nb_conda_kernels
2) Close the anaconda application altogether
3) Open anaconda, and under the "Applications on __________" (upper left dropdown menu in the anaconda main menu view), I selected "anaconda3"
4) Open Jupyter Lab (perhaps Jupyter notebook will also work)
5) Re-executed my code and WALA! it worked.
Let me know if you guys have any questions.