python-for-data-and-media-communication-gitbook
python-for-data-and-media-communication-gitbook copied to clipboard
cannot import Bar from pyecharts
My environment
- Device/ Operating System: ios
- Python version: python3
- Which chapter of book?: week11
My question
- I cannot import Bar from pyecharts.


The minimum code (snippet) to reproduce the issue
from pyecharts import Bar
Describe the efforts you have spent on this issue
I find the problem is normal. I Google it and find there are many people who face the same problems as mine. I have tried some ways of them to solve the problem but it dod not work.
Some similar solution: https://github.com/pyecharts/pyecharts/issues/750 https://github.com/pyecharts/pyecharts/issues/1
I tried another solution:
from pyecharts.charts import bar
It seems it works, but I am not sure if it is the proper way to solve the problem.
I find a useful Github website which is detailed, but I tried the steps and it did not work.
https://github.com/pyecharts/pyecharts
@ConnorLi96 can you help to also test this. It seems two possible causes to me:
- @MindyZHAOMinzhu is using Anaconda so the pip installation may redirect to wrong location. It is suggested to use virtual env to repeat all experiments in the open book
- May be Python version or package version break the demo code. -- in this case, we need a more sustainable solution: re-run all the codes with proper package versions, once we solve the issue, let's
pip freeze
the deps into arequirements.txt
so future readers will have less pain. We can also consider to usePipfile
which represents the latest practice in managing deps.
We can use Pipfile to create a turn-key solution, giving the same experience like using Anaconda.
I also have tried this module and face same problem in the previous weeks, and then I change to use matplotlib to finish work quickly, rather than focus on solving it. So I guess you can implement your visualization need at first, and then research it when you have leisure @MindyZHAOMinzhu
I see. Thanks for the info. It is good to have an issue even if we encounter problems. So we can fix later. It looks more like version unmatching problem. @ConnorLi96 can you help to see if installing previous version of pyecharts work? i.e. pip3 install pyecharts==x.x.x
.
v1.0.0
can import Bar.
- Step1, use
print(sys.path)
to find your packages location - Step2, cd in this path, then run
pip uninstall pyecharts
. - Step3,
!pip3 install pyecharts==v1.0.0
@MindyZHAOMinzhu
Thank you all a lot!! It works now when I use !pip3 install pyecharts==v1.0.0
. It seems there are two editions, and the other edition did not work.
I also think there are some problems with my path, when I tried !pip3 install pyecharts==v1.0.0
at first, it did not work, too. I delect all files and tried the steps which written on the pyecharts tutorial, then I found it worked.
My path is as followed,although I am not sure about the meaning😭
you can google sys.path
to understand the paths one by one. Actually, the step 1 is not compulsory, just ensure pip command is running on the python you use, and make env clear.
@MindyZHAOMinzhu can you help to revise the corresponding section, so future readers would use v1.0.0 by default?
(later we can revise the whole chapter in order to accommodate later versions of pyecharts; for the moment, fixing version number is the quickest solution).
@MindyZHAOMinzhu can you help to revise the corresponding section, so future readers would use v1.0.0 by default?
(later we can revise the whole chapter in order to accommodate later versions of pyecharts; for the moment, fixing version number is the quickest solution).
OK, I will pull the request.