Pysqlcipher3 cannot find sqllite3 shared library - python

I have custom linux OS for an ARM board.
I compiled the pysqlcipher3 for the platform in the yocto build. The python3 program fails to identify a sqlite3 symbol in the shared libraries.
>>> from pysqlcipher3 import dbapi2 as sqlcipher
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/site-packages/pysqlcipher3/dbapi2.py", line 33, in <module>
from pysqlcipher3._sqlite3 import *
ImportError: /usr/lib/python3.5/site-packages/pysqlcipher3/_sqlite3.cpython-35m-arm-linux-gnueabihf.so: undefined symbol: sqlite3_enable_load_extension
But I have added sqlite3 packages in the yocto. I identified the library in the rootfs.
/usr/lib/libsqlite3.so.0
I have checked the symbols in the library using the nm command and it seems to have the missing symbol (sqlite3_enable_load_extension).
Please help me to resolve this issue.
Some forum suggested the usage of LD_PRELOAD option, It mess ups with sqlcipher operations
when I try to opne the database I get this error
getSingle failed file is encrypted or is not a database

The pysqlcipher module depends on the libsqlcipher.so library in the device. The libsqlcipher should be built with --enable-load-extension to avoid this error
For Yocto build, I have added the flag in sqlcipher recipe file to avoid the issue.
EXTRA_OECONF = "--enable-load-extension --disable-tcl CFLAGS=-DSQLITE_HAS_CODEC"

Related

Compile the Python interpreter for embedded linux

i'm trying to build a Linux distro and i need python in it.so far i compiled everything i needed with sharde library option and copy its binary and its needed library in my distro and they are working.i compiled python with this option:
./configure --prefix="/" --enable-shared
make
and copied binary and Lib directory in my distro.it will run but i got error when i'm importing standard libraries such as socket.
>>> import socket
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/Lib/socket.py", line 47, in <module>
import _socket
ImportError: No module named _socket
I checked lib directory and socket.py is in there.
my purpose is to build a light embedded linux.compiling and and installing need so many tools and i cant just have all of them in my target.
I would appreciate if someone can help me.thank you in advanced and sorry for my English.

Cannot import ctypes on Linux

I have Linux Ubuntu x64 14.04 with Python 3.4 installed (default installation by Ubuntu).
If I open CudaText text editor, it cannot import ctypes in console:
>>>> import ctypes
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.4/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ImportError: /usr/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so: undefined symbol: PyFloat_Type
Seems like Py3.4 installation is not full? Why it cannot load ctypes?
In Debian Linux distros such as Ubuntu, Python extension modules are built assuming Python's symbols are loaded globally, so they don't explicitly list the Python lib as a requirement in the ELF header. An embedding application that links dynamically needs to load the Python shared library to the global symbol table, e.g. dlopen("libpython3.4m.so", RTLD_GLOBAL | RTLD_NOW).
The author of the CudaText editor is using Python for Lazarus. I presume this uses dynlibs. As you can see in the source, it does not call dlopen with RTLD_GLOBAL. The default is RTLD_LOCAL (0).

importing psutil into web2py: "ImportError: DLL load failed: %1 is not a valid Win32 application"

I am developing a web app using web2py. In my Python code, I have to use psutil for calculating the disk size, RAM being used, free RAM, and related information.
I have installed on my system psutil-2.1.1 for Python 2.7, and so far I had no problem with psutil.
But when I import psutil into my web2py application, I get an import error as follows:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\psutil\__init__.py", line 53, in <module>
from psutil._common import memoize
File "C:\Python27\lib\site-packages\psutil\_common.py", line 12, in <module>
import socket
File "C:\Python27\lib\socket.py", line 47, in <module>
import _socket
ImportError: DLL load failed: %1 is not a valid Win32 application.
I understand that the error means I am trying to import a 32bit-something into a 64bit-something or viceversa. Independent of web2py, psutil works just fine. I've tried running the same in a virtual environment also, and it gives the same error. As far as I know, web2py has no explicit separate installer for 32bit and 64bit, so I don't understand where the problem lies.
You can find the code where I've had to use psutil below:
#all necessary imports
import psutil
def summ_handler():
#...
disk_size = float (psutil.disk_usage(curr_dir).total)/(1024**3)
print ("System Space : %sGB " %disk_size)
#...
ram_total = float(psutil.phymem_usage().total)/(1024**3)
ram_free = float(psutil.phymem_usage().free)/(1024**3)
ram_used = ram_total - ram_free
#printing
#...
Edit:
I have included the differences in sys.path here
sys.path from web2py
C:\Python27\web2py\site-packages
C:\Python27\web2py
C:\Python27\web2py\gluon
C:\Python27\lib\site-packages\setuptools-5.4.1-py2.7.egg
C:\Python27\lib\site-packages\distribute-0.6.49-py2.7.egg
C:\Python27\web2py\library.zip
C:\Python27
C:\Python27\lib\site-packages
C:\Python27\lib\site-packages\win32
C:\Python27\lib\site-packages\win32\lib
C:\Python27\lib\site-packages\Pythonwin
C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg-info
C:\Python27\web2py\gluon
sys.path for an ordinary script. psutil works here.
C:\Python27\lib\site-packages\setuptools-5.4.1-py2.7.egg
C:\Python27\lib\site-packages\distribute-0.6.49-py2.7.egg
C:\windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
C:\Python27\lib\site-packages\win32
C:\Python27\lib\site-packages\win32\lib
C:\Python27\lib\site-packages\Pythonwin
C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg-info

win32com DLL load failed

I'm trying to add win32com to Python 2.7. After looking at this, I added the directory with the _init file (Python27\Lib\site-packages\win32com) but I still get it. I went so far as to try to add a bunch of different folders to the path that seem to have to deal with win32com but I still get the error. If it knows where the file is and I added that folder to PYTHONPATH, why is this happening? I'm using PyDev with Eclipse Juno. My code:
import win32com.client
print("hello world")
when I try to run this, i get this error
Traceback (most recent call last):
File "C:\Users\Daniel\EclipseWorkspace\PhotoScript\src\scriptLaunch.py", line 1, in <module>
import win32com.client
File "C:\Python27\Lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: The specified module could not be found.
in my case typing in cmd:
python C:\Python27\Scripts\pywin32_postinstall.py -install
cmd Windows
I hope this helps
Try installing ActivePython, it includes win32com:
The Python for Windows Extensions (PyWin32 version 214).
The interface to the Win32 API (win32api).
The interfaces to Win32 COM (win32com and win32comext).
The Pythonwin Development Environment.
*ActivePython is fully binary compatible with python.org Python builds to ensure that 3rd-party binary extensions just work*
Try to install python for windows extensions:
https://sourceforge.net/projects/pywin32/files/pywin32/Build%20210/

Tried to import _mysql through MySQLdb and get the error

I'm trying to use MySQLdb and when I try to import it I get the following error. Any thoughts? I'm currently using an ubuntu instance on aws.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
>>>
Is libmysqlclient-dev installed? Package might not be exact, but thats the general idea.
Is this comment thread of any help?
Try updating /etc/ld.so.conf so as to include the directory in which you've installed this.
After struggling with this same issue myself (on the AWS Linux I AMI), I found the answer
here:
While the comment thread already posted was helpful, Apache was clearing my environment variables, so setting LD_RUN_PATH and/or LD_LIBRARY_PATH was not effective.
What ended up working was adding a new include statement to /etc/ld.so.conf and running ldconfig.

Categories

Resources