使用pyecharts做地图Map的数据分析安装echarts-china-cities-pypkg地图数据包报错

最近 在学习数据可视化方面的课程,在进行到使用pyecharts对地图作数据展示的时候,需要安装几个地图数据包,按照课程PPT里的说法,先安装echarts-countries-pypkg和echarts-china-provinces-pypkg这两个地图数据,分别为国家和中国的身份数据,这里我是管理员身份打开的Windows下的命令提示符进行的安装,为什么要特意提及安装方式,下面会说明原因。上面两个数据包安装直接2条命令过去无比顺利,当安装到echarts-china-cities-pypkg时,命令行就可就炸了,下面是我提取的一部分报错,我会简单分析下,因为我只能管中窥豹下可能的原因。

C:\Users\xxxx>pip install echarts-china-cities-pypkg
Collecting echarts-china-cities-pypkg
Using cached echarts-china-cities-pypkg-0.0.9.tar.gz (4.0 MB)
Preparing metadata (setup.py) ... done
Requirement already satisfied: lml>=0.0.2 in c:\users\xxxx\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from echarts-china-cities-pypkg) (0.1.0)
Requirement already satisfied: pyecharts-jupyter-installer==0.0.3 in c:\users\xxxx\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from echarts-china-cities-pypkg) (0.0.3)
Using legacy 'setup.py install' for echarts-china-cities-pypkg, since package 'wheel' is not installed.
Installing collected packages: echarts-china-cities-pypkg
Running setup.py install for echarts-china-cities-pypkg ... error
ERROR: Command errored out with exit status 1:
command: 。。。。。
'C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\echarts_china_cities_pypkg\resources\echarts-china-cities-js\gui4_zhou1_qian2_dong1_nan2_miao2_zu2_tong1_zu2_zi4_zhi4_zhou1.js': No such file or directory
ERROR: Command errored out with exit status 1: 'C:\Users\xxxx\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\xxxx\\AppData\\Local\\Temp\\pip-install-qmkfizol\\echarts-china-cities-pypkg_b1a6c5b470da43258e2d2f299f8cf6c7\\setup.py'"'"'; __file__='"'"'C:\\Users\\xxxx\\AppData\\Local\\Temp\\pip-install-qmkfizol\\echarts-china-cities-pypkg_b1a6c5b470da43258e2d2f299f8cf6c7\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\xxxx\AppData\Local\Temp\pip-record-smwkl2c0\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Include\echarts-china-cities-pypkg' Check the logs for full command output.

从上面错误输出的后面,可以大致了解,是说缺少“gui4_zhou1_qian2_dong1_nan2_miao2_zu2_tong1_zu2_zi4_zhi4_zhou1.js”这个js文件,然后既然你说缺少这个文件,那我就到github上把这个文件下载下来,然后放到提示C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\echarts_china_cities_pypkg\resources\echarts-china-cities-js\的目录,这样再次安装总行了吧。然鹅是我大意了,错误并没有闪躲。

再次运行安装命令,还是上面同样的报错。这就然我很是蛋疼了,我思来想去不会是网络问题吧,然而我使用指定安装源的方法:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple echarts-china-cities-pypkg

还是报同样的错误,说我有地图数据不存在那个目录,这也太不给面子了吧,你说你没有数据,我亲手把数据交于你,你还是舔着个批脸和我说“给我数据”,你可是真够逗得。那既然不是网络问题,那我根据pip仓库里的第2种安装方法,再试一下吧。

git clone https://github.com/pyecharts/echarts-china-cities-pypkg.git
cd echarts-china-cities-pypkg
python setup.py install

结果还是给我报没有文件或目录的错误,或者说无法创建目录,不一而足,但是我是按照他的报错改正的,比如说以管理员权限运行命令提示符cmd,缺少js数据文件,我下载下来放进你说的目录,那么既然你命令提示符里是这个错误,那我试试Anaconda Powershell Prompt安装一下如何,这次一试,倒是给我了另外的排查问题的思路,执行pip命令后,错误如下,唯一和命令提示符下不太一样的是我下面黏贴的错误:

Anaconda Command Prompt

 ERROR: Fail copying build\lib\echarts_china_cities_pypkg\resources\echarts-china-cities-js\gui4_zhou1_qian2_dong1_nan2_miao2_zu2_tong1_zu2_zi4_zhi4_zhou1.js -> build\bdist.win-amd64\wheel\.\echarts_china_cities_pypkg\resources\echarts-china-cities-js
error: could not create 'build\bdist.win-amd64\wheel\.\echarts_china_cities_pypkg\resources\echarts-china-cities-js\gui4_zhou1_qian2_dong1_nan2_miao2_zu2_tong1_zu2_zi4_zhi4_zhou1.js': No such file or directory
------------------------------ERROR: Failed building wheel for echarts-china-cities-pypkg
Running setup.py clean for echarts-china-cities-pypkg
Failed to build echarts-china-cities-pypkg
Installing collected packages: pyecharts-jupyter-installer, lml, echarts-china-cities-pypkg
Running setup.py install for echarts-china-cities-pypkg ... done
DEPRECATION: echarts-china-cities-pypkg was installed using the legacy 'setup.py install' method, because a wheel could not be built for it. A possible replacement is to fix the wheel build issue reported above. You can find discussion regarding this at https://github.com/pypa/pip/issues/8368.
Successfully installed echarts-china-cities-pypkg-0.0.9 lml-0.1.0 pyecharts-jupyter-installer-0.0.3

上面提到的如果要安装这个数据包,不可以用pip了,用使用遗产方法setup.py install去代替,但讲点道理,我之前用过这个方法,你不还是给我报错吗?既然这样,那就死马当活马医吧,我就在anaconda command prompt下运行以下命令:

cd echarts-china-cities-pypkg 
python setup.py install

这次总算没有那么一大串让人心生恐惧的大串红色报错了:

(base) PS C:\Users\xxxx> cd .\echarts-china-cities-pypkg\
(base) PS C:\Users\xxxx\echarts-china-cities-pypkg> python setup.py install
running install
Installing pyecharts module...
running build
running build_py
running egg_info
writing echarts_china_cities_pypkg.egg-info\PKG-INFO
writing dependency_links to echarts_china_cities_pypkg.egg-info\dependency_links.txt
writing requirements to echarts_china_cities_pypkg.egg-info\requires.txt
writing top-level names to echarts_china_cities_pypkg.egg-info\top_level.txt
reading manifest file 'echarts_china_cities_pypkg.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'echarts_china_cities_pypkg\resources\echarts-china-cities-js\*.js'
warning: no files found matching 'echarts_china_cities_pypkg\resources\registry.json'
writing manifest file 'echarts_china_cities_pypkg.egg-info\SOURCES.txt'
running install_lib
copying build\lib\echarts_china_cities_pypkg\_version.py -> C:\Users\xxxx\anaconda3\Lib\site-packages\echarts_china_cities_pypkg
copying build\lib\echarts_china_cities_pypkg\__init__.py -> C:\Users\xxxx\anaconda3\Lib\site-packages\echarts_china_cities_pypkg
running install_egg_info
removing 'C:\Users\xxxx\anaconda3\Lib\site-packages\echarts_china_cities_pypkg-0.0.9-py3.8.egg-info' (and everything under it)
Copying echarts_china_cities_pypkg.egg-info to C:\Users\xxxx\anaconda3\Lib\site-packages\echarts_china_cities_pypkg-0.0.9-py3.8.egg-info
running install_scripts
Installing javascript extensions echarts-china-cities-js ...
error: [Errno 2] No such file or directory: 'echarts_china_cities_pypkg/resources/echarts-china-cities-js\\..\\registry.json'

这里就比较明朗一些了,说是我在某个目录下缺少registry.json文件,那我就找到这个文件,然后 把它放到某个目录,再试下:

我找到包含registry.json文件的目录为:C:\Users\xxxx\anaconda3\Lib\site-packages\echarts_china_cities_pypkg\resources

把目录下的文件和echarts-china-cities-js文件夹,复制到下面的目录:C:\Users\xxxx\echarts-china-cities-pypkg\echarts_china_cities_pypkg\resources

这里的xxxx请根据自己的用户名进行替换,不要我这里是xxxx,你就认为我是骗子,你自己的系统肯定不会有xxxx这个用户的,除非你自己就创建了一个这种用户。

安装需要复制的文件和目录

再次运行 python setup.py install命令,这次总算安装成功了。不得不说学习某些与Python相关的知识,是比较方便,该有的包都有,但是对第三方包的管理机制,我感觉有点肆意妄为了,无意给初学者带来了很大的时间成本,明明一条命令可以解决的问题,非得让我到处寻找解决方案,然后自己摸索出这种很不优雅的解决方法。我觉得这个锅开发者是不是要背呢?

2021年11月25日                                        添加评论

In pyecharts, 数据可视化

# # #

发表回复