1

I want to use json parser in my python script. When I import json module there is an 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'
>>> 

I supposed that in python3 json is built-in. Python is running on - arm imx6, yocto 2.2, python 3.5.2

So how can I install json module?

Thank you

Edit - add output of test.py script:

try:
    import json
except ImportError:
    import simplejson as json

output:

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'

2 Answers 2

3

Yocto creates embedded systems: this is why python does not automatically come with all of the modules it usually does. Whoever created the image you're using had the option of including all standard modules but did not do that.

If you are building your own image you can include more python packages in your image install, either python3-json for just what you need or something like python3-modules to get all the common ones: see meta/recipes-devtools/python/python3/python3-manifest.json for more details on the split.

EDIT: Actually, you are using an old Yocto version so probably want to look at meta/recipes-devtools/python/python-3.5-manifest.inc for the details

Sign up to request clarification or add additional context in comments.

1 Comment

I run - bitbake python-json and than i copy files in deploy (directory lib-dynload/ and json), now it's working. Thank you
0

In your case you can try this code snippet:

try:
    import json
except ImportError:
    import simplejson as json

you can visit python json module import error

4 Comments

Thank you for reply, I added output of script. I have no simplejson (like in the link - they use python2.6)
json this default package in python. if you have not json then you can upgrade your python version or if want to work same installed python then install json (pip install jsons)[pypi.org/project/jsons/]
It's embedded linux, there is no pip (and I cannot install pip because yocto...)
last option is upgrade python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.