如何为anaconda python3安装gi模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37526026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install gi module for anaconda python3?
提问by Kossak
python3
is my local Anaconda version of python, while python3.4
is the system one. 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
是我的本地蟒蛇版本的python,而python3.4
系统版本是。我可以导入gi
模块python3.4
(可能是因为我用 安装了它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? Or maybe i can somehow import sysem-wide modules?
我应该如何gi
为 Anaconda python安装?或者我可以以某种方式导入系统范围的模块?
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
采纳答案by Kossak
This is how you do it: (example for Linux Mint and python3)
这就是你的方法:(Linux Mint 和 python3 的示例)
First install gi
module using your distro package manager. For Linux Mint it would be:
首先gi
使用发行版包管理器安装模块。对于 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
. Assuming you have your anaconda installed in /home/kossak/anaconda3
, create a link to gi module in the proper folder:
所以在我的情况下,模块gi
被安装到/usr/lib/python3/dist-packages/gi
. 假设您已将 anaconda 安装在 中/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. Assuming the virtual env is called TEST:
如果你有 conda 虚拟环境并希望gi
模块在那里可用,路径应该有点不同。假设虚拟环境称为 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
>>>
回答by Yuvraj Jaiswal
If you're using conda virtualenv for python-3, you can use
如果您在 python-3 中使用 conda virtualenv,则可以使用
$ conda install -c conda-forge pygobject
in your virtualenv
在你的虚拟环境中
You can read more about this on: https://anaconda.org/conda-forge/pygobject
您可以在以下位置阅读更多相关信息:https: //anaconda.org/conda-forge/pygobject
回答by DGoiko
If you want to perform a proper install (without soft linking) inside a Linux anaconda environment. 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). Install it if you don't know very well what you're doing to avoid missunderstandings
如果您想在 Linux anaconda 环境中执行正确的安装(没有软链接)。请记住,如果您之前没有安装 gcc,错误可能会有所不同(我假设在我发布时默认安装了它,但并不是每个人都这样做)。如果您不太清楚自己在做什么,请安装它以避免误解
Create or open your conda environment.
Attemp to install pygobject (don't worry, it will most likely throw an error):
pip install pygobject
In linux, it will promp the usual installation progress followed by an error:
(...) Please, try executing the following in your system: 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. 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.
Close your conda environment
conda deactivate
Next you need to install pygobject from conda-forge repository in your conda environment. 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). 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:
which conda
Open the conda environment
source activate <your env name>
or the corresponding anaconda activate syntax (I never use it so I cant remember precisely)
Repeat the first step and now the installation wont fail:
pip install pygobject
OR if you specifically want to install gi you can run:
pip install pgi
the correct package is "pgi" NOT "gi"
创建或打开您的 conda 环境。
尝试安装 pygobject(别担心,它很可能会抛出错误):
pip install pygobject
在linux下,它会提示通常的安装进度,然后是一个错误:
(...) 请尝试在您的系统中执行以下命令: sudo apt install libgirepository1.0-dev
根据您的操作系统或安装的依赖项,命令名称或包名称可能会有所不同。只需按照说明操作并允许系统安装您的数据包。这一步不会改变任何东西,只是为您提供系统上所需软件包的准确信息。如果你在 Windows 上运行它,它会要求你安装特定版本的 Visual Studio。如果您使用的是 Windows,请从 MS 网站下载所需的 Visual Studio,安装它,重新启动计算机并转到第 5 步(在我的情况下,我从不需要在 Windows 中执行第 4 步,但是,我不是 MS 专家。
关闭您的 conda 环境
conda deactivate
接下来,您需要在 conda 环境中从 conda-forge 存储库安装 pygobject。您可以将 repo 添加到您最喜欢的 conda 包管理器中,或者只需以 root 身份运行以下命令(成为 root 很重要)。我是在项目外做的,但你可以在里面做:
conda install -c conda-forge pygobject
就我而言, conda 不在路径中。我已经安装在:
/opt/anaconda3/bin/
您可以从普通用户运行以下命令以找出 conda 的位置:
which conda
打开conda环境
source activate <your env name>
或相应的 anaconda activate 语法(我从不使用它,所以我记不清了)
重复第一步,现在安装不会失败:
pip install pygobject
或者,如果您特别想安装 gi,您可以运行:
pip install pgi
正确的包是“pgi”而不是“gi”
As gi is a dependency of pygobject, everything will get properly installed. You can check it by running
由于 gi 是 pygobject 的依赖项,所以一切都会被正确安装。您可以通过运行来检查它
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 绑定
回答by ChaosPredictor
for me
为了我
conda install -c pkgw/label/superseded gtk3
worked
工作过