美文网首页
Pyecharts snapshot_selenium 错误 W

Pyecharts snapshot_selenium 错误 W

作者: 王叽叽的小心情 | 来源:发表于2020-09-16 20:10 被阅读0次

在采用pyecharts进行绘图的时候,需要将渲染的html文件输出为图片格式,主要用到了selenium包,主要代码如下。

    from snapshot_selenium import snapshot
    from pyecharts.render import make_snapshot   
    
    # 中间代码...

    geo.render(out_path+'test.html')  # 这一步没问题
    make_snapshot(snapshot, geo.render("test.html"), output_name="geo_city_fci.png", 
                  pixel_ratio=3, delay=1) # 输出图片有问题

但是出现了错误,错误提示: raise WebDriverException( WebDriverException: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

错误原因:需要安装Chromedriver

解决方法:

  1. 查看当前Chrome版本,在浏览器输入 chrome://version/ 即可查看
    当前浏览器版本
  2. 下载对应版本的Chromedrive,官网:https://sites.google.com/a/chromium.org/chromedriver/ (需要翻墙),打不开可以用镜像网址:http://npm.taobao.org/mirrors/chromedriver,对应版本自己看着下载。
  3. 解压下载的包,得到.exe执行文件
    方法一(本人失败了):
  4. 将下载的.exe执行文件复制到的Chrome浏览器的安装路径中,如下图所示


    复制Chromedriver到Chrome的安装路径
  5. 添加Chromedriver到系统环境变量,右击电脑,属性,接下来如下图
    添加环境变量
    然而,此种方法并没有成功,make_snapshot(snapshot, geo.render("test.html"), output_name="geo_city_fci.png", pixel_ratio=3, delay=1)语句依然有错误。
    方法二(本人成功了):
  6. 将chromedriver.exe文件复制到了python安装路径的根目录下,如下图所示,成功啦。注意需要是对应的运行的Python根目录。


    复制到python的根目录下

第二种方法就成功了,想来也是,不用靠系统环境变量了,直接放在Python环境下了。

参考资料:
https://www.jianshu.com/p/dc0336a0bf50 (第一种方法)
https://www.cnblogs.com/yetj/p/10016462.html(第二种方法)

相关文章

网友评论

      本文标题:Pyecharts snapshot_selenium 错误 W

      本文链接:https://www.haomeiwen.com/subject/jxvhyktx.html