我試圖運行下面的程序:ModuleNotFoundError:無模塊命名爲 'GI' - Python的 - OSX
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
卜我越來越:
Traceback (most recent call last):
File "application.py", line 2, in <module>
import gi
ModuleNotFoundError: No module named 'gi'
我在一臺Mac塞拉利昂( 10.12.1(16B2555))使用python3。
我已經安裝pygoject和GTK + 3(因爲在這裏可以看到):
(cv) ✔ ~/Documents/test
00:53 $ brew install pygobject3 --with-python3 gtk+3
Warning: pygobject3 3.24.1_1 is already installed
Warning: gtk+3 3.22.18 is already installed
我的蟒蛇是從我的virtualenv:
(cv) ✘-1 ~/Documents/test
00:53 $ which python
/Users/myuser/.virtualenvs/cv/bin/python
(cv) ✔ ~/Documents/test
00:54 $ python --version
Python 3.6.1
如果我嘗試卸載GI重新安裝它(如我在Stack的一些以前的答案中看到的)我得到:
(cv) ✘-1 ~/Documents/test
00:55 $ pip uninstall gi
Cannot uninstall requirement gi, not installed
任何想法可以解決我的問題?
在此先感謝
我的第一個猜測是,您使用的的virtualenv的python但GI安裝在您的系統目錄。你可以停用你的virtualenv,嘗試啓動python並導入gi嗎?如果這有效,我們可以找出一些東西。 –
嘗試重新創建環境,因爲綁定是針對系統Python安裝的 - 所以它們可能不會反映在您的(舊)環境中。執行'pip freeze> requirements.txt'來捕獲已安裝的內容,然後重新創建環境,然後嘗試。 –
@NoufalIbrahim顯然這是因爲:10:18 $ python Python 2.7.10(默認,2016年7月30日,18:31:42) [GCC 4.2.1兼容Apple LLVM 8.0.0(鐺800.0。 34)]在達爾文 輸入「幫助」,「版權」,「信用」或「許可證」以獲取更多信息。 >>> import gi >>> gi.require_version('Gst','1.0') – Gabrielle