Cannot import ctypes on Linux - python

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).

Related

Pysqlcipher3 cannot find sqllite3 shared library

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"

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.

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/

Can't import EasyDialogs - ImportError: No module named _Dlg

I'm trying to use the EasyDialogs python module to produce some simple dialog boxes for my python script on OSX. Whenever I try and import the EasyDialogs module I get the following error:
>>> import EasyDialogs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/EPD64.framework/Versions/6.2/lib/python2.6/plat-mac/EasyDialogs.py", line 24, in <module>
from Carbon.Dlg import GetNewDialog, SetDialogItemText, GetDialogItemText, ModalDialog
File "/Library/Frameworks/EPD64.framework/Versions/6.2/lib/python2.6/plat-mac/Carbon/Dlg.py", line 1, in <module>
from _Dlg import *
ImportError: No module named _Dlg
I've tried doing easy_install Carbon, as I thought it may be due to some issue with the Carbon package for python, but that hasn't helped. Any ideas?
From the paths in your traceback, you appear to be using a 64-bit Enthought Python Distribution. The EasyDialogs module uses various OS X Carbon interfaces, many of which OS X only provides 32-bit versions and have been deprecated by Apple. For this reason, the Python Carbon wrapper and EasyDialogs modules are deprecated in Python 2 and have been removed in Python 3. While they may work in 32-bit mode, you should avoid using them in new code. There are other alternatives available: Tkinter in the standard library, various cross platform GUI frameworks (see here). For more simple dialogs, you could also use the osax package in appscript to use the User Interaction suite of AppleScript's Standard Additions.

Categories

Resources