Importing _mysql in MySQLdb - python

Why is _mysql in the MySQLdb module a C file? When the module tries to import it, I get an import error. What should I do?

It's the adaptor that sits between the Python MySQLdb module and the C libmysqlclient library. One of the most common reasons for it not loading is that the appropriate libmysqlclient library is not in place.

Edit: This might be the answer to your question.
When I try to import _mysql, I get no error:
import _mysql
print(_mysql)
# <module '_mysql' from '/usr/lib/pymodules/python2.6/_mysql.so'>
It is importing the library /usr/lib/pymodules/python2.6/_mysql.so
If this is not what you are getting, it sounds like an installation error.
What OS are you using?
How did you install mysqldb?

Related

How to import things in Python stub files?

I'm annotating types for the aiojira library using stub files. aiojira library follows the same structure as jira library. jira library contains resilientsession module, so I think I should create resilientsession.pyi file and import it in __init__.pyi. I did this, but when write:
import aiojira.resilientsession
PyCharm complains, mypy complains:
kgjirawebhook/__init__.py:7: error: Cannot find module named 'aiojira.resilientsession'
How do I fix this?
This might be because aiojira is not installed in your current environment. Relative import should fix this problem.
Try:
from . import resilientsession

Unable to import package NetworkSecurityGroupsOperations of Azure in python

From azure.mgmt.network.operations import NetworkSecurityGroupsOperations
ImportError: No module named operations
Error in importing submodule operations from this package
Version of the package is: azure-Mgmt-network==2.0.0 rc2
You can use code like below to import NetworkSecurityGroupsOperations:
from azure.mgmt.network.v2017_09_01.operations.network_security_groups_operations import NetworkSecurityGroupsOperations
You can get more details with this link and you can change the v2017_09_01 with which version you need.

No module named 'iap_pkcs7_verifier' for iap_local_receipts python

I installed iap_local_receipts on python3 after solving issues with M2crypto and openSSL, just to find out that python cannot resolve the import iap_pkcs7_verifier:
.../iap_receipt_verifier.py", line 1, in <module>
from iap_pkcs7_verifier import PKCS7Verifier
ImportError: No module named 'iap_pkcs7_verifier'
The repo is:
https://github.com/SilentCircle/iap-local-receipt
It has the missing source code for iap_pkcs7_verifier. How can I install directly from the repo?
Any other way to solve this issue?
Unfortunately, M2Crypto doesn't support Py3 yet, which means that this library can't yet run on Py3 :/

How to use blist module without installing it?

Without installing blist, I am trying to use blist_1.3.6 module by setting the environment variable PYTHONPATH. However I am still getting the error below. Is there any way to use this _blist without installing it? I can see _blist.c is C language file.
File "/path/blist-1.3.6/blist/__init__.py", line 2, in <module>
from blist._blist import *
ImportError: No module named _blist
_blist is the module implemented by the object that results from compiling _blist.c and creating a shared library from it. You can't simply import _blist.c directly.

Change Python Versions to call two different modules

I have a simple program in which I am using two modules i.e. sqlite3 and twython. Now the sqlite3 is for python2.6 and twython is for 2.7. So if I change my shebang line to 2.6 then twyhton fails i.e.
python2.6 t_first.py
ImportError: No module named twython
And if I do following
python2.7 t_first.py
ImportError: No module named _sqlite3
Any solution.
Also virtualenv is not a best solution here.
sqlite3 is usually a builtin for python (in 2.6 and 2.7). I suggest that you install a non-broken version of python 2.7, and install twython into the site-packages for that. If you don't want to do that, install twython into the 2.6 site-packages.
you could use exception handling to manage the import process. Something along the lines of:
try:
import twython
except ImportError:
import _sqlite3
This works if you assume that you need either one of the two present in any context. This would provide a preference to twython and fall back to _sqlite3 if twython is not available. It is an acceptable logical equivalent to:
if "twython exists" import twython else import _sqlite3
If you want to be more specific about the environments you could also do the following:
import sys
if sys.version_info == (2, 6):
import _sqlite3
elif sys.version_info == (2, 7):
import twython

Categories

Resources