我想在python脚本中使用json解析器。当我导入json模块时,有一个ImportError:
root@msc-nr-imx6x:~# python3
Python 3.5.2 (default, Aug 9 2017, 22:59:34)
[GCC 6.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'json'
>>> 我认为在python3,json是内置的。Python正在运行着imx6,Yocto2.2,python3.5.2
那么我如何安装json模块呢?
谢谢
编辑-添加test.py脚本的输出:
try:
import json
except ImportError:
import simplejson as json产出:
root@msc-nr-imx6x:~# python3 test.py
Traceback (most recent call last):
File "test.py", line 2, in <module>
import json
ImportError: No module named 'json'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 4, in <module>
import simplejson as json
ImportError: No module named 'simplejson'发布于 2021-05-27 08:59:17
Yocto创建了嵌入式系统:这就是为什么python并不会自动附带它通常使用的所有模块。不管是谁创建了您所使用的映像,都可以选择包含所有标准模块,但没有这样做。
如果您正在构建您自己的映像,您可以在映像安装中包含更多的python包,或者使用python3-json来获取您所需要的东西,或者类似于python3-modules来获取所有常见的包:有关拆分的更多细节,请参见python3-json。
编辑:实际上,您使用的是一个老的Yocto版本,因此可能需要查看meta/recipes-devtools/python/python-3.5-manifest.inc的详细信息。
发布于 2021-05-27 04:41:40
在您的例子中,您可以尝试以下代码片段:
try:
import json
except ImportError:
import simplejson as jsonhttps://stackoverflow.com/questions/67715723
复制相似问题