在 virtualenv 中安装 PyGtk
所以我尝试在我的 virtualenv 中(在控制台中)运行一个简单的 matplotlib 示例。这是代码:
import matplotlib
matplotlib.use('GTKAgg')
import matplotlib.pyplot as plt
radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724]
plt.plot(radius, area)
plt.show()
但是,当我运行它时,我得到:
导入错误:Gtk* 后端需要安装 pygtk。
现在有趣的事情开始了。我尝试 pip install pygtk 但它抛出:
********************************************************************
* Building PyGTK using distutils is only supported on windows. *
* To build PyGTK in a supported way, read the INSTALL file. *
********************************************************************
Complete output from command python setup.py egg_info:
********************************************************************
我已经检查了 INSTALL
文件并说尝试 ./configfure;制作;进行安装
。然而。我不太确定如何在 virtualenv 中执行此操作。我在哪里解压 pygtk 的源代码才能安装在 virtualenv 中。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
诀窍是手动设置正确的路径,然后在 virtualenv 中运行配置。这是非常基本的,但它对我有用。
在虚拟环境中安装 python-config 并将其链接到 python2.7-config:
在虚拟环境中安装 cairo:
安装 PyGTK
这样就可以了。只需将 PATH/TO/VIRT/ 替换为您自己的路径即可。我确信有人可以协助添加 virtualenvwrapper 的路径?
The trick is to manually set the correct paths and then run configure inside the virtualenv. This is quite basic, but it worked for me.
Install python-config in the virtual env and link it to python2.7-config:
Install cairo in the virtual env:
Install PyGTK
And that should do it. Just replace PATH/TO/VIRT/ with your own path. I'm sure someone could assist on adding the path to virtualenvwrapper?
我做了这个
我发现它已经安装了一些调查,我发现当我创建虚拟环境时,它缺少一些链接,所以我遇到了这篇文章:
Ubuntu 上的 Virtualenv,没有站点包。
我阅读了它并定制了为我的设置提供的命令,如下所示:
首先,我更改为我的 virtualenv 并通过
激活它
然后我执行了以下命令。
最后,检查我输入了“python”并执行:
<前><代码>>>>导入pygtk
它没有给我错误,因此我知道它现在在我的虚拟环境中可用。
我在 intel Core i5 上使用 Ubuntu 14.04(64 位)。
I did this
I found that it was already installed upon some investigation, i found out that when I create a virtual environment, it was missing some links so I came across this post:
Virtualenv on Ubuntu with no site-packages.
I read it and tailored the commands provided to my setup as follows:
First I changed into my virtualenv and activated it by
Then I changed into the lib/python2.7 folder inside my virtualenv:
I then executed the following commands.
Finally, to check I typed 'python', and executed:
It gave me no error, and therefore I knew its now available in my virtual env.
I'm using Ubuntu 14.04 (64-bit) on an intel Core i5.
pygtk
无法从 PyPI 安装到您的 virtualenv 中,因此将下载但不会安装。您可以完成下载 tar 文件并编译和安装这些文件的过程,但是如果可以链接到系统中安装的相关软件包,则激活您的 virtualenv 并安装
ruamel.venvgtk
就足够了:这是我自己工作的无耻插件,这里没有其他解决方案与重复的 virtualenv 创建配合得很好,例如由
tox
完成的。在软件包的 setup.py 中,会发生以下情况:
即询问系统的 python pygtk 安装在哪里(在 Linux Mint 17.1 上,这是 /usr/lib/python2.7/dist- package),然后将链接设置为激活的 python 的第一个路径(非零长度)。
pygtk
cannot be installed in your virtualenv from PyPI, sowill download but not install. You can go through the hoops of downloading the tar files and compiling and installing those, but if it is OK to make links to the relevant packages installed in the system then activating your virtualenv and installing
ruamel.venvgtk
is enough:This is a shameless plug for my own work, none of the other solutions here worked well with repeated virtualenv creation as is e.g. done by
tox
.In the
setup.py
of the packages the following happens:i.e the system's python is asked where pygtk is installed (on Linux Mint 17.1 this is
/usr/lib/python2.7/dist-packages
), and then links are set up to the first path (that is non-zero length) for the activated python.我的经验(仅在 Posix 系统上)是某些软件包无法安装在 virtualenv 中(我认为这是因为它们需要自行编译等)。有时它们可以随后安装在单独的包中。
处理这种情况的一种方法是在其他地方编译并安装该包,然后配置 virtualenv 以通过添加站点包路径来加载该包。查看文档了解更多信息。 (或者设置一个 boostrap 脚本,每次激活环境时都会更改环境路径(使用
virtualenvwrapper
My experience (on Posix systems exclusively) has been that some packages cannot be installed in
virtualenv
(I think it's because they need to compile themselves, etc). Sometimes they can be installed in the individual package afterwards.One way you could handle this situation is to compile and install the package somewhere else and then configure the virtualenv to load that package by adding site-packages paths. Check out the documentation for more. (or setup a boostrap script that changes the environment path every time you activate your environment (easy to do with
virtualenvwrapper
我通过安装 python-gtk2 debian 包解决了这个问题。
I fixed the problem by installing the python-gtk2 debian package.
我在支持 gtk 的 Linux 系统上使用 python 3.10。
没有一个解决方案适合我,而且我无法找到 gtk 的替代安装。
但我注意到在全局python环境中有这个库并且你可以使用它。正如您所了解的,您无法一次选择多个虚拟环境,但您想要测试许多其他库。
总的来说,这就是我的想法。创建了一个名为 venv 的本地虚拟 python shell。
它包含位于 venv/lib/python3.10/site-packages/ 的库。
在全局环境中,库存储在这里/usr/lib/python3/dist-packages/。
我需要的 gtk 全局环境中的目录称为“gi”。
接下来我做了一个符号链接。
现在它在本地 venv 中看起来像这样:
奇怪的是,它有效。
也许这只是某种拐杖。
I'm using python 3.10 on a Linux system with gtk support.
Not a single solution worked for me, plus I couldn’t figure out the alternative installation of gtk.
But I noticed that in the global python environment there is this library and you can use it. And as you understand, you can’t select several virtual environments at once, but you want to test a lot of other libraries.
In general, this is what I came to. Created a local virtual python shell called venv.
It contains libraries at venv/lib/python3.10/site-packages/.
In the global environment, the library is stored here /usr/lib/python3/dist-packages/.
The directory in the gtk global environment that I needed is called "gi".
Next I made a symbolic link.
Now it looks like this in the local venv:
Strangely enough, it works.
Perhaps this is just some kind of crutch.