2016-05-30 4 views
7

python3 ist meine lokale Anaconda-Version von Python, während python3.4 das System ist. Ich kann gi Modul mit python3.4 importieren (wahrscheinlich, weil ich es mit sudo apt-get install python3-gi installiert), aber python3 es nicht sieht:Wie installiere ich ein gi-Modul für anaconda python3?

$ 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 
$ 

Wie soll ich gi für Anaconda Python installiert werden? Oder kann ich irgendwie sysemweite Module importieren?

Mein o:

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 

Antwort

8

Dies ist, wie Sie es tun: (Beispiel für Linux Mint und python3)

Erste gi Modul mit Ihrem Distro Paket-Manager installieren. Für Linux Mint wäre es:

sudo apt-get install python3-gi 

Dann Ihre Distro Python ausführen, um herauszufinden, wo das Modul befindet:

$ /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'> 

Also in meinem Fall das Modul gi-/usr/lib/python3/dist-packages/gi installiert wurde. Vorausgesetzt, dass Sie Ihre Anakonda in /home/kossak/anaconda3 installiert haben, erstellen Sie einen Link zu gi Modul im richtigen Ordner:

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

Wenn Sie Conda virtuelle Umgebung und wollen gi Modul dort zur Verfügung stehen, sollte der Pfad ein wenig anders sein. Unter der Annahme, die virtuelle env wird TEST genannt:

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

und es funktioniert:

$ 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 
>>> 
1

Wenn Sie Conda virtualenv für Python-3 verwenden, die Sie verwenden können Ihre

$ conda install -c conda-forge pygobject 

in virtualenv

Sie können mehr lesen auf: