Compile the Python interpreter for embedded linux - python

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.

Related

Not able to install bz2 in Python 3

I am not able to install the bz2 package in Python 3 Can please anyone guide
I followed the below commands
sudo yum install bzip2-devel
after that, I start my python 3.7 terminal and use the below command
import bz2
The error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/sysopt/lib/python3.7/bz2.py", line 19, in <module>
from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'
Based on the comments and the /usr/local/sysopt path, I assume you've installed Python 3.7 from a source package.
When you did that, the Python configure script checked whether it has the bits to compile the bz2 module, and as you didn't have bzip2-devel installed during that time, the builtin bz2 module didn't get compiled.
You will need to recompile and reinstall Python 3.7 to get it included. At that point, you may also want to pay heed to any other optional modules that inadvertently don't get installed; sqlite3 tends to usually be one that ends up missing!

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"

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

Custom python install location: tkinter problems

I'm using Ubuntu 14.04. While I have to retain my "main" python install as 2.7.6, I need to install 2.7.9 to be able to use ssl.SSLContext, to get Flask to deal with HTTPS requests.
However, if I just do:
sudo make install
or
sudo make altinstall
in the Python-2.7.9 directory, I ultimately get:
make: *** [libinstall] Error 1
EDIT: this appears at the end of sudo make install:
...
Compiling /usr/local/lib/python2.7/xml/sax/saxutils.py ...
Compiling /usr/local/lib/python2.7/xml/sax/xmlreader.py ...
Compiling /usr/local/lib/python2.7/xmllib.py ...
Compiling /usr/local/lib/python2.7/xmlrpclib.py ...
Compiling /usr/local/lib/python2.7/zipfile.py ...
make: *** [libinstall] Error 1
So I installed it to a custom directory by modifying the call to ./config, which did not yield the libinstall error.
However, when I try to import Tkinter into Python 2.7.9 (running from the custom directory) I obtain:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/repos/Python279/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
If I just go ahead and install the vanilla way (i.e., to a non-custom directory) and simply ignore the libinstall error I get, upon importing Tkinter:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: /usr/lib/python2.7/lib-dynload/_tkinter.so: undefined symbol: PyFPE_jbuf
Does anyone have any idea what is going on?
Following furas' suggestion, installing via the
Python 2.7 PPA maintained be Felix Krull worked spectacularly. Thanks Furas!
EDIT Some notes:
Because this PPA installs python2.7 (specifically v. 2.7.11, as of 1/29/2016), this obviated the need for a custom python install location
While the PPA website mentions that this doesn't include python-tk, provided you have installed it, python plays with it just fine (solving my problem)
First of all source code from a program must be configured, compiled, then installed. You can do this by:
./configure # Or ./config depending on the file name
make
make install
Second of all when you tried to import the module _tkinter you wanted to import the .py file which was called Tkinter.py
Try to use:
import Tkinter

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/

Categories

Resources