[英]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.