天天看點

pyecharts報錯 ImportError: cannot import name ‘options‘ from ‘pyecharts‘ 解決方法版本更換其他問題終極方案

版本更換

使用pycharm安裝最新版本1.9.0

pyecharts報錯 ImportError: cannot import name ‘options‘ from ‘pyecharts‘ 解決方法版本更換其他問題終極方案

成功解決

其他問題

修改最新版本後可能出現不能導入子產品的問題

pyecharts報錯 ImportError: cannot import name ‘options‘ from ‘pyecharts‘ 解決方法版本更換其他問題終極方案

可以通過修改

from pyecharts import Pie
form pyecharts import Bar
           

from pyecharts.charts import Pie
from pyecharts.charts import Bar
           

但是在這種情況下,相關庫的使用方法會有所變化,仍會出錯,需要按照特定版本API進行開發

pyecharts報錯 ImportError: cannot import name ‘options‘ from ‘pyecharts‘ 解決方法版本更換其他問題終極方案

是以建議開始時确定好固定版本,在此基礎上進行開發

終極方案

同時安裝多個pyecharts版本,不同版本代碼調用不同的pyecharts版本

首先安裝一個版本的pyecharts,而後将其名字修改為pyecharts_1,避免被另一安裝版本覆寫

而後使用pycharm安裝另一版本的pyecharts

pyecharts報錯 ImportError: cannot import name ‘options‘ from ‘pyecharts‘ 解決方法版本更換其他問題終極方案

由此安裝多個版本的pyecharts

此時調用1.90版本pyecharts需要使用如下代碼

from pyecharts_190 import options as opts
from pyecharts_190.charts import Tree
           

中間會報錯,是因為庫中的路徑未修改,需要同樣修改為pyecharts_190

__init__.py

pyecharts報錯 ImportError: cannot import name ‘options‘ from ‘pyecharts‘ 解決方法版本更換其他問題終極方案

globals.py

pyecharts報錯 ImportError: cannot import name ‘options‘ from ‘pyecharts‘ 解決方法版本更換其他問題終極方案

在修改的過程中會出現不能修改成功的現象,可以通過将整個檔案夾移出,并修改後複制替換原有檔案

繼續閱讀