简体   繁体   English

即使安装了Python,也找不到PyGObject / gi

[英]Python can't find PyGObject/gi even though it is installed

I have trouble setting up the Python-Path for it, I don't really know what to do here. 我在为其设置Python路径时遇到了麻烦,我真的不知道该怎么做。 I use elementary OS, which should be similar enough to Ubuntu. 我使用基本操作系统,应该与Ubuntu足够相似。

My code so far is this: 到目前为止我的代码是这样的:

#!/usr/bin/python3
import gi
gi.require_version('GTK', '3.0')

When I run the script, the system reports that there is no module named "gi". 运行脚本时,系统报告没有名为“ gi”的模块。 However, when I try 但是,当我尝试

sudo apt-get python3-gi

I get told that it is installed already. 我被告知它已经安装。 I tried 我试过了

print(sys.path)

and

locate python3-gi

which gave me back some directories. 这给了我一些目录。 But there were too many, so I don't know what, if this is at all the right way, to to copy where. 但是有太多,所以我不知道该复制正确的位置(如果正确的话)。

Addendum: 附录:

Okay, so doing type export PATH="$PATH:/usr/local/bin/python-gi3" yields export is a shell builtin bash: type: PATH=/home/ge0rg/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/bin/python3-gi: not found 好的,所以执行type export PATH="$PATH:/usr/local/bin/python-gi3"产生export is a shell builtin bash: type: PATH=/home/ge0rg/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/bin/python3-gi: not found

uname -r yields 3.19.0-51-generic . uname -r产生3.19.0-51-generic

In the meantime, I also tried reinstalling python3-gi, to no avail. 同时,我也尝试重新安装python3-gi,但无济于事。 Also, since python3-gi seems to b located in /usr/lib/python3/dist-pacakges , I tried going into python and doing sys.path.append("/usr/lib/python3/dist-pacakges") where the above mentioned folder was not included before. 另外,由于python3-gi似乎位于/usr/lib/python3/dist-pacakges ,所以我尝试进入python并执行sys.path.append("/usr/lib/python3/dist-pacakges")上面没有提到文件夹。 However, after doing this import gi gives the same error as before: >>> import gi Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'gi' 但是,执行此操作后, import gi会提供与以前相同的错误: >>> import gi Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'gi'

EDIT: Also, locate python3-gi yields: 编辑:另外, locate python3-gi yields:

`/usr/share/doc/python3-gi
/usr/share/doc/python3-gi-cairo
/usr/share/doc/python3-gi/changelog.Debian.gz
/usr/share/doc/python3-gi/copyright
/usr/share/doc/python3-gi-cairo/changelog.Debian.gz
/usr/share/doc/python3-gi-cairo/copyright
/usr/share/lintian/overrides/python3-gi
/var/lib/dpkg/info/python3-gi-cairo.list
/var/lib/dpkg/info/python3-gi-cairo.md5sums
/var/lib/dpkg/info/python3-gi-cairo.postinst
/var/lib/dpkg/info/python3-gi-cairo.postrm
/var/lib/dpkg/info/python3-gi-cairo.shlibs
/var/lib/dpkg/info/python3-gi.list
/var/lib/dpkg/info/python3-gi.md5sums
/var/lib/dpkg/info/python3-gi.postinst
/var/lib/dpkg/info/python3-gi.postrm
/var/lib/dpkg/info/python3-gi.prerm
/var/lib/dpkg/info/python3-gi.shlibs`

however, /usr/lib/dist-packages/gi also exists, but locate gi just gives back a whole array of mostly unrelated results. 但是, /usr/lib/dist-packages/gi也存在,但是locate gi只会返回locate gi几乎不相关的结果。

I am guessing its installed in /usr/local/bin/python-gi3 . 我猜它安装在/usr/local/bin/python-gi3 If you see it there, open your shell and type type export PATH="$PATH:/usr/local/bin/python-gi3" to set the path 如果在此处看到它,请打开外壳并键入export PATH="$PATH:/usr/local/bin/python-gi3"来设置路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使正确安装,Python3仍找不到模块 - Python3 won't find a module even though it is properly installed python3即使安装了也无法导入dbus - python3 Can't import dbus even though it's installed 即使安装了软件包,也无法解析 python 导入模块 - Can't resolve python import module even though packages are installed 即使安装了 pygame 也无法导入 - Can't import pygame even though it is installed Python 模块已安装也找不到 - Python Module Can Not be Found Even Though It Is Installed 即使导入成功,Python也找不到类 - Python can't find class even though the import was successful pyautogui / pyscreeze 找不到枕头,即使它已成功安装到同一个 package 文件夹中,我可以导入它 - pyautogui / pyscreeze can't find pillow even though it is successfully installed into the same package folder and I can import it 即使模块位于路径中,Django manage.py也找不到INSTALLED_APP - Django manage.py can't find an INSTALLED_APP even though the module is in the path 即使pip已安装pyflake,Emacs Elpy Flymake也找不到pyflakes - Emacs elpy Flymake can't find pyflakes even though pyflake has been installed by pip Python 找不到 LibTIFF 库,即使已经安装了 LibTIFF - Python cannot find LibTIFF library, even though LibTIFF is already installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM