Error importing gi - python

This is the command I am trying to run and its output:
$ python2
Python 2.7.8 (default, Sep 24 2014, 18:26:21)
[GCC 4.9.1 20140903 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/gi/__init__.py", line 42, in <module>
from . import _gi
ImportError: /usr/lib/python2.7/site-packages/gi/_gi.so: undefined symbol: g_type_check_instance_is_fundamentally_a
I have searched for this error, but could not find anything that helped.
These are the packages that I have installed:
$ pacman -Qs python
local/pygtk 2.24.0-3
Python bindings for the GTK widget set
local/python 3.3.4-1
Next generation of the python high-level scripting language
local/python-dbus-common 1.2.0-2
Common dbus-python files shared between python-dbus and python2-dbus
local/python-gobject 3.14.0-2
Python 3 bindings for GObject
local/python-gobject2 2.28.6-11
Python 3 bindings for GObject2
local/python2 2.7.8-2
A high-level scripting language
local/python2-cairo 1.10.0-1
Python2 bindings for the cairo graphics library
local/python2-dbus 1.2.0-2
Python 2.7 bindings for DBUS
local/python2-distutils-extra 2.38-1
Enhancements to the Python build system
local/python2-gobject 3.14.0-2
Python 2 bindings for GObject
local/python2-gobject2 2.28.6-11
Python 2 bindings for GObject2
local/python2-pillow 2.3.0-3
Python Imaging Library (PIL) fork. Python2 version.
local/python2-xdg 0.25-1
Python library to access freedesktop.org standards
Dont know what I am missing here..
Solved:
Error was due to older version of glib2 package.

This might be not a Python problem nor your code problem. /usr/lib/python2.7/site-packages/gi/_gi.so might be corrupted or compiled badly. Maybe you've put it in the wrong path.
How to solve: upgrade glib2

Related

Python 3.11 installation: some modules are missing

I'll try to be as clear and specific as possible because I've seen so many people with the same problem, but none of the answers they had worked for me.
The problem in question is: missing modules when trying to import other modules, that (by far as I understand) are installed by default in Python 3.11. eg: missing _sqlite3 when importing sqlite3.
Python 3.11.0 (main, Jan 12 2023, 03:19:52) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user_name/opt/Python-3.11.0/lib/python3.11/sqlite3/__init__.py",
line 57, in <module> from sqlite3.dbapi2 import *
File "/home/user_name/opt/Python-3.11.0/lib/python3.11/sqlite3/dbapi2.py",
line 27, in <module> from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
Context
I'm currently working on a Dreamhost VPS, running on Ubuntu 20.04.5. Since it's a Dreamhost VPS keep in mind I can't uso sudo.
I've Python 3.8 installed globally, but I'm trying to set Python 3.11 with venv. The steps to install Python 3.11 were, as indicated by 'Installing a custom version of Python 3 by Dreamhost':
cd /home/user_name/opt
wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz
tar zxvf Python-3.11.0.tgz
cd Python-3.11.0
./configure --prefix=$HOME/opt/Python-3.11.0
make
make install
When running the make command I saw the following message:
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_lzma _tkinter _uuid
readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py have not
been built, they are *disabled* by configure:
_sqlite3
This is my detect_modules() in setup.py:
def detect_modules(self):
# remove dummy extension
self.extensions = []
# Some C extensions are built by entries in Modules/Setup.bootstrap.
# These are extensions are required to bootstrap the interpreter or
# build process.
self.detect_simple_extensions()
self.detect_test_extensions()
self.detect_readline_curses()
self.detect_crypt()
self.detect_openssl_hashlib()
self.detect_hash_builtins()
self.detect_dbm_gdbm()
self.detect_sqlite()
self.detect_platform_specific_exts()
self.detect_nis()
self.detect_compress_exts()
self.detect_expat_elementtree()
self.detect_multibytecodecs()
self.detect_decimal()
self.detect_ctypes()
self.detect_multiprocessing()
self.detect_tkinter()
self.detect_uuid()
# Uncomment the next line if you want to play with xxmodule.c
# self.add(Extension('xx', ['xxmodule.c']))
self.addext(Extension('xxlimited', ['xxlimited.c']))
self.addext(Extension('xxlimited_35', ['xxlimited_35.c']))
So after running the commands I just mentioned, I proceeded to setup the virtualenv to test Python 3.11:
cd /home/user_name/opt
/home/user_name/opt/Python-3.11.0/bin/python3 -m venv venv
source venv/bin/activate
And then I got the ModuleNotFoundError I mentioned at the start of the question.
Things I tried/saw:
When I checked my Python 3.11 directory, I saw that in /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload the cpython files for the modules I don't have are just not there, e.g: /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload/_sqlite3.cpython-311-x86_64-linux-gnu.so* where as in my Python 3.8, they're indeed there: /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so
I tried copying the cpython file from my 3.8 to my 3.11 and renaming it:
cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload
mv /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload/_sqlite3.cpython-311-x86_64-linux-gnu.so
Then when I ran Python 3.11 I got the following error:
Python 3.11.0 (main, Jan 12 2023, 04:33:33) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _sqlite3 # this works just fine
>>> import sqlite3 # throws error
356306 segmentation fault (core dumped) python
Tried recompiling Python and running ./configure --prefix=$HOME/opt/Python-3.11.0 --enable-loadable-sqlite-extensions and didn't work.
Hope I was clear enough and thanks in advance.

ImportError importing ssl in MinGW-W64 Python 3.6

I've used MSYS2 to install the MinGW-W64 version of Python 3.6 (mingw-w64-x86_64-python3). Upon importing ssl, an ImportError is raised:
$ python3
Python 3.6.2 (default, Aug 15 2017, 10:59:43) [GCC 7.1.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "G:/msys64/mingw64/lib/python3.6\ssl.py", line 101, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified procedure could not be found.
>>>
I'm not sure why this. pacman shows both mingw-w64-x86_64-openssl and openssl as installed. /mingw64/lib/python3.6/lib-dynload/_ssl-cpython-36m.dll exists. Other .dll files from the same directory (like those used for the json and sqlite3 modules) import fine.
To make matters weirder, the Python 2 version (mingw-w64-x86_64-python2) doesn't have this problem.
This is not a correct solution (the MSYS2 folks are working on the real solution), but as a temporary workaround for anyone else who gets stuck on this:
After installing mingw-w64-x86_64-python3 copy
C:\msys64\mingw64\bin\LIBEAY32.dll and
C:\msys64\mingw64\bin\SSLEAY32.dll
to
C:\msys64\mingw64\lib\python3.6\lib-dynload\LIBEAY32.dll and
C:\msys64\mingw64\lib\python3.6\lib-dynload\SSLEAY32.dll respectively.
Afterwards import ssl (and tools that rely on it, like pip3) should work correctly.

Importing wxPython fails in Maya

When I try to import wxPython from Maya (or mayapy), I get an import error:
[/c] ==> mayapy
Python 2.6.4 (r264:75706, May 19 2011, 13:53:43) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Program Files\Autodesk\Maya2013\Python\lib\site-packages\wx-3.0-msw\wx\__init__.py", line 45, in <module>
from wx._core import *
File "c:\Program Files\Autodesk\Maya2013\Python\lib\site-packages\wx-3.0-msw\wx\_core.py", line 4, in <module>
import _core_
ImportError: DLL load failed: The specified module could not be found.
Question:
How do I make wxPython work with Maya's Python installation?
Context:
I use PyQt, PySide and Tkinter for my UI development with Maya Python. I want to use wxPython just to try it out. I installed the version of wxPython that was meant for Python 2.6/Win64. It is installed in Maya's Python folder: C:\Program Files\Autodesk\Maya2013\Python\lib\site-packages\
I tried installing wx for a standard installation of Python 2.6 and it works fine. That is the reason I am posting this question; I am looking for a solution for why this is happening only for the Maya Python installation and not the other standard Python installation that I have.
I am using:
Maya version: 2013
Maya Python version: 2.6.4
OS: Windows 7, 64-bit.
Thank you for any help or suggestions you can give.
There are a couple of reasons you could be getting that message. Some have reported that this happens if you install a 64-bit wxPython to a 32-bit Python (or vice-versa), although I personally don't know how you could do that. That is something to check though as if you have a 64-bit vs 32-bit mismatch, you will definitely have issues.
The other more likely issue is that you need to install a Microsoft redistributable so that you have the correct DLL that wxPython needs.
"import wx" fails after installation of wxPython on Windows XP
wxPython Import Error: DLL load failed

Can't import igraph (Python2.7) after installing on OSX

I'm trying to use python's iGraph module on my iMac running OSX 10.9.4. I've followed the steps on igraphs' front page for mac installation bur when I go to import igraph from the terminal, this is what I get.
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named igraph
Here are the steps that I've attempted to install igraph:
I intially had some problems with my pkg-config not being writable (I'm new to homebrew), so I followed these steps
brew install homebrew/science/igraph like posed here and linked the formula with brew link igraph and it brewed with no problems.
pip install python-igraph also finished cleanly.
From the igraphs documentation, this is all I need to do.
I looked into this answer but couldn't get the following line to work.
DYLD_LIBRARY_PATH=/usr/local/lib python -m igraph.test.__init__
/usr/bin/python: No module named igraph.test
This might suggest where the problem is but I don't know where to go from here.
Other information:
I have python installed through brew, but I'm not sure if that is causing the conflict. Regardless, Python2.7 should be the default python. I've installed other modules like numpy, scipy, and matplotlib with no problems.
Let me know if you need/want any other info.

Setting up: OS X 10.6.6 + XCode3.2 using python and cocoa

I am trying to set up working environment on
OS X 10.6.6, XCode3.2, fink using python and cocoa frameworks. I scanned few references in the net, however nothing worked for me.
I have python2.6 installed via fink together with a pyobjc-py26. When I run a python shell in the terminal I get:
localhost:PyObjCTut stymek$ which python
/usr/bin/python
localhost:PyObjCTut stymek$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import objc
>>>
Everything is OK.
When I try to build the basic code from the Xcode (e.g. 1. default Python + Cocoa template 2. example from here), the python is not able to find objc module. Why?
Traceback (most recent call last):
File "main.py", line 10, in <module>
import objc
ImportError: No module named objc
I was struggling with almost similar troubles after manually installing Python version 2.7 and 3.X...
There's no such setting in XCode - the Apple-shipped Python (v2.6) needs to be the default one.
Also, check in the /System/Library/Frameworks/Python.framework/Versions - the 'Current' symlink needs to point to the default Python v2.6

Categories