After installing pyecharts 1.x version or 0.5.11 version and related packages, the solution to the problem that JupyterNotebook and local html call images cannot be displayed!

Because pyecharts 1.x version and pyecharts 0.5.11 version are very different!
Therefore, no matter the code composition, the packaging method of the source code, the way of use, and the related configuration are very different. Of course they also have some of the same parts.
Regardless of whether you are using the 1.x version or the 0.5.11 version, just after installing its package and related packages, print graphics directly on Jupyter or generate local html, you may encounter JupyterNotebook and local html call images can not be displayed problem! The following is the solution to this problem for these two versions:

To solve this problem encountered in pyecharts 1.x version:

First, the reason analysis:

  1. It is not a drawing syntax error or the like, because there is no error and the syntax is normal.
  2. Could it be caused by a program conflict? This is not right, I tried it in a virtual environment.
  3. Since it is related to web pages, is it a js or css problem? ? ? Not sure, but suspicious.

So, I don’t want to guess, just go to the official website if I have something to do. No, according to the official website:
the following default value is the culprit.
Insert picture description hereInsert picture description here
Solution: official solution

  1. Get the pyecharts-assets project
 $ git clone https://github.com/pyecharts/pyecharts-assets.git

2. Install extensions

 $ cd pyecharts-assets
 # 安装并激活插件
 $ jupyter nbextension install assets
 $ jupyter nbextension enable assets/main

The execution results of the first and second steps: (Proved successful!)
Insert picture description here
3. Configure pyecharts global HOST

 # 只需要在顶部声明 CurrentConfig.ONLINE_HOST 即可
 from pyecharts.globals import CurrentConfig, OnlineHostType

 # OnlineHostType.NOTEBOOK_HOST 默认值为 http://localhost:8888/nbextensions/assets/
 CurrentConfig.ONLINE_HOST = OnlineHostType.NOTEBOOK_HOST

 # 接下来所有图形的静态资源文件都会来自刚启动的服务器
 from pyecharts.charts import Bar
 bar = Bar()

I suspected that it was a problem with echarts.min.js before, but I went to the installation directory to see it. 1.x version and 05x version are almost completely different structure:
05x version is still: (so if 05x version can not load the chart, it is very likely that these js files are missing or have problems)
Insert picture description here
1x version has abolished this method, specific Look at the explanation on the official website, there is a link above.
https://pyecharts.org/#/zh-cn/assets_host
I think it will be installed to a certain folder after installation, but I don’t know where it is. But there is no need to know, because if it fails to load again and encounters the same problem, just reinstall git cloneand install it again.

Before the above solution:
Insert picture description here
After the solution:
Insert picture description here

The solution to this problem encountered in pyecharts0.5.x version:

Look at this picture and find the following directory. If you install python directly, it may be in
\Lib\site-packages\jupyter_echarts_pypkg\resources\echarts under its installation directory , so you only need to view the files in the following photo Whichever is lost, just download the one and go in.
Of course, it is generally OK to put echart.min.js. (These files are available on the echarts official website)
Insert picture description here
Method 2: The
above is to use jupyter notebook to start the js_host acquisition service. The following is to use the local service to get js_host.
Go back to the \pyecharts-assets directory and start the http server:

python -m http.server

Set up local host:


CurrentConfig.ONLINE_HOST = "http://127.0.0.1:8000/assets/"
当然,可以直接把值换成本地路径

Question update:

Encountered a 404 error:

jupyter notebook: 404 GET /static/components/bootstrap/fonts/glyphicons-halflings-regular.woff

Encountered this error, and the previous guarantee is ok, then it is a browser problem.
Version 81.0.4044.138 (official version) (64-bit) does not work, change the version or change Firefox.

Guess you like

Origin blog.csdn.net/qq_42658739/article/details/105700349