I need to import simplemysql module. But getting ImportError. Import doesn't give error for root user.
Can you please help me with this issue?
$ python
Python 2.7.11 |Anaconda 2.5.0 (32-bit)| (default, Dec 6 2015, 18:08:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> from simplemysql import SimpleMysql
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named simplemysql
>>>
$ su
Password:
root#mtk-Inspiron-1525:/home/mtk/.anaconda2# python
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from simplemysql import SimpleMysql
>>>
These are different Pythons called in these two cases:
Python 2.7.11 |Anaconda 2.5.0 (32-bit)| (default, Dec 6 2015, 18:08:45)
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
Check that you have simplemysql installed into the 2.7.11 Anaconda one.
I had a similiar problem and i found out that i can only work with the Module if i import MySQLdb first. Installation of simplemysql (as far as i remember) only worked with a cmd ran as admin on Windows 8.
Related
I am trying to install Openstack(Victoria) on my ubuntu 20.04 and getting below error.
File "/usr/local/bin/cinder-manage", line 6, in <module>
from cinder.cmd.manage import main
File "/opt/stack/cinder/cinder/cmd/manage.py", line 75, in <module>
from cinder.db import migration as db_migration
File "/opt/stack/cinder/cinder/db/migration.py", line 26, in <module>
from cinder.db.sqlalchemy import api as db_api
File "/opt/stack/cinder/cinder/db/sqlalchemy/api.py", line 45, in <module>
from sqlalchemy.orm import joinedload, joinedload_all, undefer_group, load_only
ImportError: cannot import name 'joinedload_all' from 'sqlalchemy.orm' (/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/__init__.py)
'```
I have tried installing using ```pip install sqlalchemy.orm ```
joinedload_all was removed in 1.4 release notes
You can try capping the version to less than 1.4 like this:
pip install 'sqlalchemy<1.4'
I'm not sure if openstack uses a virtualenv but you probably will want to install its dependencies in something like.
You should always be installing requirements with constraints applied for the version you are deploying.
pip install -c https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/victoria sqlalchemy
This will ensure that you are installing the recommended version for the OpenStack release you are using.
You could also try to just re-install all the requirements for cinder with the correct versions.
cd /opt/stack/cinder pip install -c https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/victoria /opt/stack/cinder/requirements.txt
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
I have a 5 line Python script which is failing.
GCP indicates a problem with a GCP-API permissions issue.
I'm not sure though it is telling me the truth.
Here is the Python syntax:
import googleapiclient.discovery
compute = googleapiclient.discovery.build('compute', 'v1')
project_s = 'shining-sol-241621'
zone_s = 'us-central1-a'
result = compute.instances().list(project=project_s, zone=zone_s).execute()
The above syntax depends on this env variable setting:
export GOOGLE_APPLICATION_CREDENTIALS=$HOME/secret.json
When I run the Python syntax I see:
$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import googleapiclient.discovery
>>> compute = googleapiclient.discovery.build('compute', 'v1')
>>> project_s = 'shining-sol-241621'
>>> zone_s = 'us-central1-a'
>>> result = compute.instances().list(project=project_s, zone=zone_s).execute()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/googleapiclient/http.py", line 851, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/compute/v1/projects/shining-sol-241621/zones/us-central1-a/instances?alt=json returned "Required 'compute.instances.list' permission for 'projects/shining-sol-241621'">
>>> >>>
Above, I see this msg in the error:
"Required 'compute.instances.list' permission for 'projects/shining-sol-241621'"
At this URL:
https://console.cloud.google.com/iam-admin/iam?project=shining-sol-241621
When I look at the service-account permissions attached to my secret.json file I see that I have attached these permissions to the account:
Compute Admin
Compute Instance Admin (beta)
Compute Instance Admin (v1)
Compute Viewer
Security Admin
Owner
When I attached permissions to the service-account, I saw no permission available which looked like:
'compute.instances.list'
I did note that the Compute Admin permission has this description:
"Full control of all Compute Engine resources"
That description suggests to me that the permission should be able to do: 'compute.instances.list'
I am suspicious that GCP is telling me that I have a permissions problem but the problem is somewhere else.
Based on my description, what would be some good questions to ask in order to move past this bad API behavior?
I was able to fix this problem after I assumed that the GCP server was caching bad info.
I created a service account with a name I had not used in the past.
I gave it just one permission: Project - Owner
I asked it to create a JSON-key.
I copied the key into $HOME/secret.json
I issued shell command:
export GOOGLE_APPLICATION_CREDENTIALS=$HOME/secret.json
I tried my 6 lines of Python:
$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import googleapiclient.discovery
>>> compute = googleapiclient.discovery.build('compute', 'v1')
>>> project_s = 'shining-sol-241621'
>>> zone_s = 'us-central1-a'
>>> result = compute.instances().list(project=project_s, zone=zone_s).execute()
>>> result['items'][0]['status']
'RUNNING'
>>>
>>>
As you can see, it worked.
Yay!
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 :)
I want to call legacy c third party functions from python.
I created a C api to make the function calls simpler.
In my python file
I tried to import the *.so for the api which links with the legacy code library.
But I kept seeing a libxxx ( the legacy c library) not found error.
I tried to import both ans still saw the same error.
I then tried using ctypes, but get the error ctypes not found.
Any suggestions ?
# python
Python 2.4.2 (#1, Apr 20 2012, 19:31:49)
[GCC 4.1.2 20070115 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named ctypes
>>> quit
ctypes only made it into the standard library in version 2.5, so 2.4 does not have it. I've also heard that some people exclude it when they build Python for a distribution or for embedding in a specific application, as you can easily crash your process using it, or even corrupt the host application's heap. But I have never encountered this myself, and I doubt a full installation does this.
As for not finding your C library, we'll need more details on that.