python3 中没有名为 json 的模块
No module named json in python3
我想在我的 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 是 运行 - arm imx6,yocto 2.2,python 3.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'
在你的情况下,你可以试试这个代码片段:
try:
import json
except ImportError:
import simplejson as json
您可以访问
Yocto 创建嵌入式系统:这就是为什么 python 不会自动附带它通常附带的所有模块。创建您正在使用的图像的人可以选择包括所有标准模块,但没有这样做。
如果您要构建自己的映像,则可以在映像安装中包含更多 python 包,python3-json
满足您的需要,或者 python3-modules
之类的东西以获得所有常见的:请参阅 meta/recipes-devtools/python/python3/python3-manifest。json 了解有关拆分的更多详细信息。
编辑:实际上,您使用的是旧 Yocto 版本,所以可能想查看 meta/recipes-devtools/python/python-3.5-manifest.inc 了解详细信息
我想在我的 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 是 运行 - arm imx6,yocto 2.2,python 3.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'
在你的情况下,你可以试试这个代码片段:
try:
import json
except ImportError:
import simplejson as json
您可以访问
Yocto 创建嵌入式系统:这就是为什么 python 不会自动附带它通常附带的所有模块。创建您正在使用的图像的人可以选择包括所有标准模块,但没有这样做。
如果您要构建自己的映像,则可以在映像安装中包含更多 python 包,python3-json
满足您的需要,或者 python3-modules
之类的东西以获得所有常见的:请参阅 meta/recipes-devtools/python/python3/python3-manifest。json 了解有关拆分的更多详细信息。
编辑:实际上,您使用的是旧 Yocto 版本,所以可能想查看 meta/recipes-devtools/python/python-3.5-manifest.inc 了解详细信息