"ELF file OS ABI invalid" using psycopg2 - python

I've post a question, but I think the problem is maybe specific. So I create this new post.
When I test in the python's console psycopg2, I've this error :
this-user#xxx-web:~/my-folder$ python
Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys,os
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/users/this-user/.local/lib/python2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: /home/users/this-user/.local/lib/python2.7/site-packages/psycopg2/_psycopg.so: ELF file OS ABI invalid
>>> quit()
this-user#xxx-web:~/massifs$ ll /home/users/this-user/.local/lib/python2.7/site-packages/psycopg2/_psycopg.so
-rwxr-xr-x 1 this-user 214K mai 21 2015 /home/users/this-user/.local/lib/python2.7/site-packages/psycopg2/_psycopg.so*
If I run the python's console in root, it's working !!?? :(
Thanks for help.
F.

Note that your import is from a 'user' install, so if you run it as root, it will import something else (a different copy of the module which happens to work). You may have two installs of the psycopg2 module and the one that is in this-user is not compatible (maybe you copied it directly from another host rather than installing it with pip).
You should probably un-install psycopg2 and re-install it properly with python -m pip uninstall --user psycopg2 and then python -m pip install --user psycopg2, so you get the correct build of the .so file.

Related

How to install tkinter for python3.10.6 on CentOS7?

First, I installed openssl 1.1.1q package using the following source on CentOS7.
(https://www.openssl.org/source/openssl-1.1.1q.tar.gz)
Second, I installed tcl/tk packages using the following sources.
(https://prdownloads.sourceforge.net/tcl/tcl8.6.12-src.tar.gz
https://prdownloads.sourceforge.net/tcl/tk8.6.12-src.tar.gz)
Finally, I installed python 3.10.6 using the following source.
(https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tar.xz)
However, I can't use tkinter module.
For example, when I import tkinter I get the bellow message.
Python 3.10.6 (main, Aug 18 2022, 11:15:38) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/tkinter/__init__.py", line 37, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
The yum doesn't support the python 3.10.x version. How can I resolve this problem without yum?
What should I do to use tkinter?
You are importing tkinter in a wrong way, it is like this
import tkinter
tkinter is a preinstalled library in python, to test it open cmd and type
python -m tkinter
a small window should appear, if it does then it is working

How to import a package that use absolute import in python

I'm trying to import volatility3 into my python project/script, so that I don't have to use os.system since volatility3 is already made in python3.
I'm wondering how can I import all the functions/modules of said project ? The functions I'm interested in are located in volatility3/volatility/framework
I tried simply putting:
>>> import volatility3.volatility.framework
But I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/volatility3/volatility/framework/__init__.py", line 12, in <module>
from volatility.framework import constants, interfaces
ModuleNotFoundError: No module named 'volatility'
My guess is I have to modify sys.path or one of the path variables but this does not seem to work.
Thanks,
The best solution here would be to properly install volatility with pip3, from your already exiting repository folder:
$ pip3 install /home/volatility3
or directly from pipy (not tested):
$ pip3 install volatility3
then you should be able to import the from volatility package directly:
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import volatility.framework
>>> volatility.framework
<module 'volatility.framework' from '/home/bruno/.local/lib/python3.6/site-packages/volatility/framework/__init__.py'>
>>>

python import works interactively but not from script

Disclaimer: I'm not a Windows expert, so this may be something idiosyncratic to Windows.
I'm observing a situation where I can import a module in interactive mode but not when requested from a file. Here is foo.py in its entirety:
#!/usr/bin/env python
import pyftdi
When I try to run this in Python 3.6.4, it fails:
E:\>py foo.py
Traceback (most recent call last):
File "foo.py", line 2, in <module>
import pyftdi
ImportError: No module named pyftdi
...but when I import the module interactively, it succeeds:
E:\>py
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyftdi
>>>
(FWIW, I don't get an error when repeating this under Mac OS X.)
Any thoughts about what's going on?
The problem is most likely that the version of python is different and has different modules installed. To fix this you can simply do py -3.6 foo.py instead of py foo.py.
Working directory
I had a situation where the script was importing from it's working directory and the shell was importing from the global libraries.

How do I diagnose ImportError: DLL load failed when loading native Windows python modules in a virtualenv?

I am using Python 3.x and a virtualenv -- not conda, just a plain virtualenv.
I activate the venv and run pip install opencv-python. However,
import cv2 gives me a DLL not found error:
(tf) C:\>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\src\venv\tf\lib\site-packages\cv2\__init__.py", line 4, in <module>
from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.
>>>
Is this a virtualenv bug? How do I figure out which module/dll is missing?
On resolving "module could not be found" errors in general
Try using either Microsoft's Dependency Walker or lucasg's Dependencies on the module being loaded. Be sure to run Dependencies.exe from your virtualenv's command prompt, so it picks up your modified PATH.
The import line is from .cv2 import *, so the module being loaded is in the same directory as __init__.py (this is the leading .) and named cv2-SOMETHING.pyd (this is what native Python modules look like). Load that file into Dependencies.exe and it will show you the DLL that Windows wants but can't find.
In this case, the DLL is Python3.dll. Why is it missing? Because of a virtualenv bug that is fixed, but hasn't made its way into a release -- there hasn't been a release in more than a year.
On resolving this issue in particular
The github issue suggests a fix: use venv.
Alternatively you can copy the missing python3.dll into your virtualenv by hand. You'll have to do this for every virtualenv you create.
copy "c:\Program Files\Python36\python3.dll" "c:\src\venv\tf\Scripts\"

salesforce python Beatbox import error

I am trying to log in to salesforce.com's sandbox using a URL, ID and PASS. I want to use SOAP API for that. When I try to import beatbox in python3, it throws an ImportError exception. However, I can confirm that beatbox is installed in python3. So what am I doing wrong? Is there any other way to do it?
Python 3.5.0 (default, Dec 6 2015, 17:23:12)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import beatbox
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/site-packages/beatbox-32.1-py3.5.egg/beatbox/__init__.py", line 1, in <module>
ImportError: No module named '_beatbox'
>>>
The beatbox module that you probably installed is this : Beatbox 32.1.
Solution 1 : The above beatbox module only supports python 2.x (tested with python 2.7). So, switch to Python 2.x if that is an option.
You can find the source by original author of beatbox here and it has been updated to support python3.
Solution 2 :
Clone the repo in your local machine using git clone https://github.com/superfell/Beatbox.git
Change to the Beatbox directory
Install the module using python setup.py install
For me the issue was I had both beatbox and beatbox3 installed.
beatbox3 is the version for python3.
Once I uninstalled beatbox it worked fine.

Categories

Resources