No module named json in python3 - json

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'

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

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

Related

Get programmatically Python3 default path in Octave base directory

I am using GNU Octave. I have script written in python3 and it is working if I do something like that: (it's .m file)
setenv PYTHON python;
[output,status]=python('python_file.py');
output
But some users do not have installed Python on their own. I found that python3.exe is available in "C:\Program Files\GNU Octave\Octave-6.2.0\usr\bin" for default users.
It is possible to get Octave default path and then setenv python pointing to GNU Octave Python directory programically, everything wrote in octave_file.m?
Python file:
import sys
import subprocess
python = sys.executable
subprocess.check_call([python, '-m', 'pip', 'install', 'numpy'], stdout=subprocess.DEVNULL)
import math
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
...
result from octave:
/usr/bin/python.exe: No module named pip
Traceback (most recent call last):
File "C:\Users\X\Desktop\cw1.py", line 9, in <module>
subprocess.check_call([python, '-m', 'pip', 'install', 'numpy'], stdout=subprocess.DEVNULL)
File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python.exe', '-m', 'pip', 'install', 'numpy']' returned non-zero exit status 1.

I am encountering module loading problem in mysql

I will work with mysql, but it gives this error anyway. I did delete the module but it did not change, I loaded it differently, I could not solve the modules.
Traceback (most recent call last):
File "C:\Users\INAL\Desktop\Son Scriptler\mysql\mysql.py", line 1, in <module>
import mysql.connector
File "C:\Users\INAL\Desktop\Son Scriptler\mysql\mysql.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql.connector'; 'mysql' is not a package
You might not have the mysql-connector did you try installing it using pip?
pip3 install mysql-connector
The problem was that my project name was mysql.py and I solved the problem by changing the project name.

ImportError: No module named google.appengine.ext

I have just got the release pipeline working with Google's push to deploy on App Engine.
I released that some of my unit tests were failing.
======================================================================
ERROR: Failure: ImportError (No module named google.appengine.ext)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 414, in loadTestsFromName
addr.filename, addr.module)
File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/var/jenkins/workspace/deployment_5175583809994752_1410355681821/tests.py", line 9, in <module>
from cfc.search.nosqlhelper import set_meeting_date
File "/var/jenkins/workspace/deployment_5175583809994752_1410355681821/cfc/search/nosqlhelper.py", line 3, in <module>
from cfc.models.event import Event
File "/var/jenkins/workspace/deployment_5175583809994752_1410355681821/cfc/models/event.py", line 3, in <module>
from google.appengine.ext import ndb
ImportError: No module named google.appengine.ext
----------------------------------------------------------------------
Ran 1 test in 0.270s
I tried to run the following from python REPL in the VM containing Jenkins provisioned automatically via release pipeline in Google Developer Console.
from google.appengine.ext import ndb
I got the following error.
ImportError: No module named google.appengine.ext
I logged into the VM and noticed that the files are located at for instance:
var/lib/docker/aufs/mnt/bbc6deda44e4806c5c0e377df6f1109733e382e8531c1c9ed440084d8e98e3fe/google-cloud-sdk/platform/google_
appengine/google/appengine/ext/ndb/utils.py
How do I se the path universally in the VM ?

Kivy pygame error

I've been trying to get Kivy to work on my Mac (Lion), but I've been encountering issues. I followed the instructions on the Kivy site, and since Kivy 1.8 supports Python 3, I wanted to run it with 3.3, and I finally got that to work, by editing the kivy file to point to 3.3 instead of 2.7. I tried drop a .py program on the Kivy icon, the app opened but nothing happened. So I tried to run it from the command line. It opened 3.3, as expected, but I got the following error.
Python 3.3.4 (default, Mar 6 2014, 20:14:14)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/Kivy.app/Contents/Resources/lib/sitepackages/pygame/__init__.py", line 127, in <module>
from pygame.base import *
ImportError: dlopen(/Applications/Kivy.app/Contents/Resources/lib/sitepackages/pygame/base.so, 2): Symbol not found: _PyCObject_Type
Referenced from: /Applications/Kivy.app/Contents/Resources/lib/sitepackages/pygame/base.so
Expected in: flat namespace
in /Applications/Kivy.app/Contents/Resources/lib/sitepackages/pygame/base.so
I have no idea why I would get this error, since I previously installed pygame for 3.3, and import pygame or from pygame.base import * work error free. Would this issue with pygame explain why .py files fail to execute when I drop them onto the Kivy icon?
Kivy.app and all the dependencies included in it is compiled with and for Python 2.7. You cannot use it for 3.3.
If you want to try Kivy with 3.3, you also need to compile Kivy yourself :)

ImportError: No module named exceptions

i'm trying to install kitsune in the ubuntu terminal. I am not able to initialize the database. When i give the command ./manage.py syncdb --migrate , i get the following error
Error: Tried importing 'settings_local.py' and 'settings.py' but neither could be found (or they're throwing an ImportError). Please come back and try again later.Traceback (most recent call last):
File "./manage.py", line 30, in <module>
from kitsune import settings # Assumed to be in the same directory.
File "/home/user/kitsune/kitsune/settings.py", line 740, in <module>
import djcelery
File "/usr/local/lib/python2.7/dist-packages/djcelery/__init__.py", line 22, in <module>
from celery import current_app as celery # noqa
File "/usr/local/lib/python2.7/dist-packages/celery/five.py", line 307, in __getattr__
module = __import__(self._object_origins[name], None, None, [name])
File "/usr/local/lib/python2.7/dist-packages/celery/_state.py", line 20, in <module>
from celery.utils.threads import LocalStack
File "/usr/local/lib/python2.7/dist-packages/celery/utils/__init__.py", line 24, in
<module>
from celery.exceptions import CPendingDeprecationWarning, CDeprecationWarning
File "/usr/local/lib/python2.7/dist-packages/celery/exceptions.py", line 13, in <module>
from billiard.exceptions import ( # noqa
ImportError: No module named exceptions
I can't find the exceptions file in billiard. How do I fix this error?
I had this error with fabric. The error message was the same:
ImportError: No module named exceptions
It turned out to be my fabric was out of date. The error was resolved by upgrading fabric to the latest version (1.10) with:
$ sudo pip install fabric --upgrade
For your information, I am running Ubuntu 12.04 64-bit with Python 2.7.3
Exceptions should be a python file in a directory called billiard, for example, you create a file called exceptions.py and add the classes and methods that you need .. this can work around the problem.
You should follow kitsune installation process described in http://kitsune.readthedocs.org/en/latest/hacking_howto.html
There is a link to separate chapter on vendor-packages http://kitsune.readthedocs.org/en/latest/vendor.html#vendor-chapter. You should install all the vendor packages needed by kitsune including billiard and celery (your errors).