2016-05-30 282 views
7

python3是我本地的蟒蛇版本的python,而python3.4是系統之一。我可以導入gi模塊python3.4(可能是因爲我有sudo apt-get install python3-gi安裝了),但python3並不這麼看:如何爲anaconda python3安裝gi模塊?

$ python3 -c 'import gi' 
Traceback (most recent call last): 
    File "<string>", line 1, in <module> 
ImportError: No module named 'gi' 
$ python3.4 -c 'import gi'          

$ python3 --version 
Python 3.5.1 :: Anaconda 4.0.0 (64-bit) 
$ python3.4 --version 
Python 3.4.3 
$ which python3 
/home/kossak/anaconda3/bin/python3 
$ which python3.4 
/usr/bin/python3.4 
$ 

我應該如何安裝gi對於蟒蛇蟒蛇?或者,也許我可以以某種方式導入全系統模塊?

我的操作系統:

System: Kernel: 3.19.0-32-generic x86_64 (64 bit gcc: 4.8.2) Desktop: Cinnamon 2.8.8 (Gtk 2.24.23) dm: mdm 
      Distro: Linux Mint 17.3 Rosa 

回答

8

這是你如何做到這一點:(例如用於Linux Mint的和python3)

首先使用你的發行版包管理器安裝gi模塊。對於Linux Mint的那就是:

sudo apt-get install python3-gi 

然後運行你的發行版的Python以檢查模塊位於:

$ /usr/bin/python3 
Python 3.5.2 (default, Sep 10 2016, 08:21:44) 
[GCC 5.4.0 20160609] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import gi 
>>> print(gi) 
<module 'gi' from '/usr/lib/python3/dist-packages/gi/__init__.py'> 

所以在我的情況下,模塊gi安裝到/usr/lib/python3/dist-packages/gi。假設你已經安裝在/home/kossak/anaconda3的森蚺,在適當的文件夾中創建一個鏈接到GI模塊:

ln -s /usr/lib/python3/dist-packages/gi /home/kossak/anaconda3/lib/python3.5/site-packages/ 

如果你有暢達虛擬環境,並希望gi模塊可用那裏,路徑應該是有點不同。假設虛擬ENV被稱爲TEST:

ln -s /usr/lib/python3/dist-packages/gi /home/kossak/anaconda3/envs/TEST/lib/python3.5/site-packages/ 

和它的作品:

$ python3 
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import gi 
>>>