简体   繁体   English

如何为anaconda python3安装gi模块?

[英]How to install gi module for anaconda python3?

python3 is my local Anaconda version of python, while python3.4 is the system one. python3是我当地的Anaconda版本的python,而python3.4是系统版本。 I can import gi module with python3.4 (probably because i installed it with sudo apt-get install python3-gi ) but python3 doesn't see it: 我可以用python3.4导入gi模块(可能是因为我用sudo apt-get install python3-gi安装它)但是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
$

How should i install gi for Anaconda python? 我应该如何为Anaconda python安装gi Or maybe i can somehow import sysem-wide modules? 或者也许我可以以某种方式导入sysem范围的模块?

My os: 我的口碑:

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

This is how you do it: (example for Linux Mint and python3) 这是你如何做到的:( Linux Mint和python3的例子)

First install gi module using your distro package manager. 首先使用您的发行包管理器安装gi模块。 For Linux Mint it would be: 对于Linux Mint,它将是:

sudo apt-get install python3-gi

Then run your distro python to check where the module is located: 然后运行你的发行版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'>

So in my case the module gi was installed to /usr/lib/python3/dist-packages/gi . 所以在我的例子中,模块gi安装在/usr/lib/python3/dist-packages/gi Assuming you have your anaconda installed in /home/kossak/anaconda3 , create a link to gi module in the proper folder: 假设您在/home/kossak/anaconda3 anaconda3中安装了/home/kossak/anaconda3 ,请在正确的文件夹中创建指向gi模块的链接:

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

If you have conda virtual environment and want gi module to be available there, the path should be a bit different. 如果你有conda虚拟环境并希望gi模块在那里可用,那么路径应该有点不同。 Assuming the virtual env is called TEST: 假设虚拟env被称为TEST:

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

and it works: 它有效:

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

If you're using conda virtualenv for python-3, you can use 如果你正在使用conda virtualenv for python-3,你可以使用

$ conda install -c conda-forge pygobject

in your virtualenv 在你的virtualenv

You can read more about this on: https://anaconda.org/conda-forge/pygobject 您可以在https://anaconda.org/conda-forge/pygobject上阅读更多相关信息

If you want to perform a proper install (without soft linking) inside a Linux anaconda environment. 如果要在Linux anaconda环境中执行正确的安装(没有软链接)。 Keep in mind that the errors may vary if you have not installed gcc previously (I assumed it was installed by default when I posted, however not everyone does so). 请记住,如果您之前没有安装过gcc,错误可能会有所不同(我假设它在我发布时默认安装,但不是每个人都这样做)。 Install it if you don't know very well what you're doing to avoid missunderstandings 如果你不太了解你正在做什么以避免误解,请安装它

  1. Create or open your conda environment. 创建或打开您的conda环境。

  2. Attemp to install pygobject (don't worry, it will most likely throw an error): 尝试安装pygobject(别担心,它很可能会抛出错误):

     pip install pygobject 

    In linux, it will promp the usual installation progress followed by an error: 在linux中,它会提示通常的安装进度,然后是错误:

    (...) Please, try executing the following in your system: sudo apt install libgirepository1.0-dev (...)请尝试在您的系统中执行以下命令:sudo apt install libgirepository1.0-dev

    Depending on your operation sistem or installed dependencies, the command name or package name may vary. 根据您的操作系统或安装的依赖项,命令名称或程序包名称可能会有所不同。 Just follow the instructions and allow the system to install your packets. 只需按照说明操作,即可让系统安装数据包。 This step doesn't change anything, is just to give you the precise info of the package you need on your system. 此步骤不会改变任何内容,只是为了向您提供系统所需软件包的准确信息。 If you run this on Windows, it will ask you to install a specific version of Visual Studio. 如果您在Windows上运行它,它将要求您安装特定版本的Visual Studio。 If you are in Windows, download the required Visual Studio from MS website, install it, reboot your computer and go to step 5 (in my case I never needed step 4 in windows, however, I'm not a MS expert. 如果您在Windows中,从MS网站下载所需的Visual Studio,安装它,重新启动计算机并转到步骤5(在我的情况下,我从不需要Windows中的第4步,但是,我不是MS专家。

  3. Close your conda environment 关闭你的conda环境

     conda deactivate 
  4. Next you need to install pygobject from conda-forge repository in your conda environment. 接下来,您需要在conda环境中从conda-forge存储库安装pygobject。 You can add the repo to your favourite conda package manager or simply run the following command as root (it is important to be root). 您可以将repo添加到您最喜欢的conda包管理器中,或者只是以root身份运行以下命令(作为root是很重要的)。 I did it outside the project, but you may do it inside: 我是在项目之外做的,但你可以在里面做:

     conda install -c conda-forge pygobject 

    In my case conda was not in the path. 在我的情况下,康达不在路上。 I had is installed in: 我安装在:

     /opt/anaconda3/bin/ 

    You can run the following command from your normal user to find out where conda is: 您可以从普通用户运行以下命令以找出conda的位置:

     which conda 
  5. Open the conda environment 打开conda环境

     source activate <your env name> 

    or the corresponding anaconda activate syntax (I never use it so I cant remember precisely) 或相应的anaconda激活语法(我从不使用它,所以我不能记得精确)

  6. Repeat the first step and now the installation wont fail: 重复第一步,现在安装不会失败:

     pip install pygobject 

    OR if you specifically want to install gi you can run: 或者,如果您特别想要安装gi,您可以运行:

     pip install pgi 

    the correct package is "pgi" NOT "gi" 正确的包是“pgi”而不是“gi”

As gi is a dependency of pygobject, everything will get properly installed. 由于gi是pygobject的依赖项,所以一切都将正确安装。 You can check it by running 你可以通过运行来检查它

python
>>> import gi

You may find the following usefull for Windows, although you may need to work it out a bit: GStreammer python bindings on Windows 您可能会发现Windows的以下用途,尽管您可能需要稍微解决一下: Windows上的GStreammer python绑定

for me 为了我

conda install -c pkgw/label/superseded gtk3

worked 工作

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM