Hello,
the virt-manger doesn’t run, it ends with error:
Traceback (most recent call last):
File "/usr/share/virt-manager/virt-manager", line 16, in <module>
import gi
ImportError: No module named 'gi'
Do you know how to fix it?
Hello,
the virt-manger doesn’t run, it ends with error:
Traceback (most recent call last):
File "/usr/share/virt-manager/virt-manager", line 16, in <module>
import gi
ImportError: No module named 'gi'
Do you know how to fix it?
Just guessing,
You might try a force re-install as follows (especially if you’ve attempted any manual re-configuration. Be sure to back up your configurations if you did do something manually)
zypper in -f libvirt
And, although not likely required or directly related to your issue it’s probably a good time to update your system as well
zypper up
TSU
It didn’t work.
Open up that file and inspect line 16 to see if it really does say it’s trying to import a module named 'gi"
If you’re not sure what you’re looking at, post your entire file either here or in a pastebin for inspection.
I’m not in front of a machine where I can compare to a known good file, but trying to make sense of, and verifying the error is a reasonable step.
Edit - Although I’m not in front of a machine, I found the file online to verify the command is correct
https://github.com/virt-manager/virt-manager/blob/master/virt-manager
According to the above, you should check your LibvirtGlib for its existence and version
TSU
Thats the only package which I’ve found:
sudo zypper search LibvirtGlib
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
---+-----------------------------+---------------------------------------------------+--------
i+ | typelib-1_0-LibvirtGLib-1_0 | GLib and GObject mapping of libvirt - gi-bindings | package
Here is the first part of the virt-manager file:
!/usr/bin/env python3
#
# Copyright (C) 2006, 2014 Red Hat, Inc.
# Copyright (C) 2006 Daniel P. Berrange <berrange@redhat.com>
#
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
import argparse
import logging
import os
import signal
import sys
import traceback
import gi
gi.require_version('LibvirtGLib', '1.0')
from gi.repository import LibvirtGLib
from virtinst import util
from virtinst import cli
from virtcli import CLIConfig
# This is massively heavy handed, but I can't figure out any way to shut
# up the slew of gtk deprecation warnings that clog up our very useful
# stdout --debug output. Of course we could drop use of deprecated APIs,
# but it's a serious quantity of churn
import warnings # pylint: disable=wrong-import-order
warnings.simplefilter("ignore")
try:
gi.check_version("3.14.0")
except (ValueError, AttributeError):
print("pygobject3 3.14.0 or later is required.")
sys.exit(1)
TSU, Never use ‘zypper up’ on a Tumbleweed system, but use
zypper dup
as per documentation.
Hi
An import error is python related, maybe switched to python3, so are there python gobject packages installed?
zypper se -i python*-gobject*
Is the python3 version installed?
A quick test;
python -c "import gi; print(gi.__spec__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '__spec__'
Fail
python2 -c "import gi; print(gi.__spec__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '__spec__'
Fail
python3 -c "import gi; print(gi.__spec__)"
ModuleSpec(name='gi', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fd3c1bdfa20>, origin='/usr/lib64/python3.6/site-packages/gi/__init__.py', submodule_search_locations='/usr/lib64/python3.6/site-packages/gi'])
working
I do have the gobject packages installed:
zypper se -i python*-gobject*
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
---+-----------------------+-----------------------------------+--------
i+ | python-gobject2 | Python bindings for GObject | package
i+ | python2-gobject | Python bindings for GObject | package
i+ | python2-gobject-Gdk | Python bindings for GObject/Gdk | package
i+ | python2-gobject-cairo | Python bindings for GObject/Cairo | package
i+ | python3-gobject | Python bindings for GObject | package
i+ | python3-gobject-Gdk | Python bindings for GObject/Gdk | package
i+ | python3-gobject-cairo | Python bindings for GObject/Cairo | package
i+ | python3-gobject2 | Python bindings for GObject | package
Neither of the quick test options work:
python -c "import gi; print(gi.__spec__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'gi'
python2 -c "import gi; print(gi.__spec__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '__spec__'
python3 -c "import gi; print(gi.__spec__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'gi'
Hi
Can you try to uninstall python3-gobject2, or does it create issues? If not then test again
bor@10:~> python2 -c 'import gi; print (gi.__file__)'
/usr/lib64/python2.7/site-packages/gi/__init__.pyc
bor@10:~>
Here is the result:
python -c 'import gi; print (gi.__file__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'gi'
**python2 -c 'import gi; print (gi.__file__)'
/usr/lib64/python2.7/site-packages/gi/__init__.pyc**
python3 -c 'import gi; print (gi.__file__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'gi'
Hi
So is python3-gobject (not python3-gobject2) installed, if not install that and test your virtual manager.
Also, your using zypper dup for your system and not zypper up?
Yes it is installed:
sudo zypper in python3-gobject
[sudo] password for root:
Loading repository data...
Reading installed packages...
'python3-gobject' is already installed.
No update candidate for 'python3-gobject-3.30.4-1.1.x86_64'. The highest available version is already installed.
Resolving package dependencies...
Nothing to do.
I do zypper dup quite often.
What says
type -p python3
python3 -c 'import sys; print(sys.path)'
That’s odd:
type -p python3
/opt/anaconda3/bin/python3
python3 -c 'import sys; print(sys.path)'
'', '/opt/anaconda3/lib/python35.zip', '/opt/anaconda3/lib/python3.5', '/opt/anaconda3/lib/python3.5/plat-linux', '/opt/anaconda3/lib/python3.5/lib-dynload', '/opt/anaconda3/lib/python3.5/site-packages']
You have anaconda installed.
When you install Anaconda, you no longer use python from the OS (applies to install on all distros), Anaconda installs its own entire ecosystem including python and gives it priority over native OS libraries by prepending its PATH (so any application will find the Anaconda files before it can search for a similar file in the main OS).
You can uninstall or disable Anaconda by removing the PATH to Anaconda or removing/deleting the entire Anaconda tree of files… or doing both.
Else, you’ll have to go talk to the Anaconda folks about the “gi” module problem…
Keep in mind though that you’ll probably find the Anaconda folks uninterested in your problem, like others similar to Anaconda they are primarily interested in distributing their own entire ecology to support their included applications and don’t prioritize outside apps.
So,
This is another example of the goodness of installing virtualization and then keeping your HostOS as uncomplicated as possible…
The problem you ran into is one of many possible similar scenarios, if you had instead installed your Anaconda in a Guest, then you would have isolated the system re-configuration in the Guest, you wouldn’t have seen this in your HostOS machine or any other guests.
TSU
Thank you a lot. I’ve uninstalled the Anaconda and it virt-manager works like a charm.