如何在virtualenv中安装python3 gi?
我正在遵循,我正在尝试在virtualenv中运行一个正常的安装。我已经通过Ubuntu软件包管理器安装了。事情是这样的:如何在virtualenv中安装python3 gi?,python,python-3.x,virtualenv,Python,Python 3.x,Virtualenv,我正在遵循,我正在尝试在virtualenv中运行一个正常的安装。我已经通过Ubuntu软件包管理器安装了。事情是这样的: :~$ mkvirtualenv py3 --python=/usr/bin/python3 Running virtualenv with interpreter /usr/bin/python3 Using base prefix '/usr' New python executable in py3/bin/python3 Also creating executab
:~$ mkvirtualenv py3 --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in py3/bin/python3
Also creating executable in py3/bin/python
Installing setuptools, pip...python
done.
(py3):~$ python
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'gi'
>>>
(py3):~$ deactivate
:~$ /usr/bin/python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>>
:~$mkvirtualenv py3--python=/usr/bin/python3
使用解释器/usr/bin/python3运行virtualenv
使用基本前缀“/usr”
py3/bin/python3中的新python可执行文件
还在py3/bin/python中创建可执行文件
安装setuptools、pip…python
完成。
(py3):~$python
Python 3.4.0(默认值,2014年4月11日,13:05:11)
[GCC 4.8.2]在linux上
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>导入gi
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为“gi”的模块
>>>
(py3):~$
:~$/usr/bin/python3
Python 3.4.0(默认值,2014年4月11日,13:05:11)
[GCC 4.8.2]在linux上
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>导入gi
>>>
正如您所看到的,python3 gi显然在virtualenv中不可用,但我不确定如何安装它,因为python3 gi是通过我的软件包管理器安装的,而不是通过pip安装的。我还没有找到合适的解决方案。当我遇到无法直接安装到virtualenv中的情况时,我会将其符号链接到那里,它工作正常(可能有例外,但这不是其中之一)
一点也不优雅;这似乎比让virtualenv完全访问所有系统软件包(通过
--系统站点软件包)更好。我通过pip
安装,这可能是一个选项。显然,它是与PyGObject
兼容的API,到目前为止,在运行Gtk
更新2018–Debian Stretch
安装GTK+3/GIR
apt install libcairo2-dev libgirepository1.0-dev gir1.2-gtk-3.0
创建一个虚拟环境
python3 -mvenv venv
python3 -mvenv venv
pyvenv-3.5 venv
source venv/bin/activate
cd venv
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig
curl -L https://cairographics.org/releases/pycairo-1.10.0.tar.bz2 | tar xj
cd pycairo-1.10.0
export ARCHFLAGS='-arch x86_64'
python waf configure --prefix=$VIRTUAL_ENV # It's ok, this will fail.
sed -i '' '154s/data={}/return/' .waf3-1.6.4-*/waflib/Build.py # Bugfix: https://bugs.freedesktop.org/show_bug.cgi?id=76759
python waf configure --prefix=$VIRTUAL_ENV # Now it should configure.
python waf build
python waf install
unset ARCHFLAGS
cd ..
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig
curl -L http://ftp.gnome.org/pub/GNOME/sources/pygobject/3.12/pygobject-3.12.2.tar.xz | tar xJ
cd pygobject-3.12.2
./configure CFLAGS="-I$VIRTUAL_ENV/include" --prefix=$VIRTUAL_ENV
make
make install
cd ..
安装pygobject
(pycairo
应作为依赖项提供)
2018年更新–macOS
使用安装GTK+3和Gobject自省
创建并激活虚拟环境
python3 -mvenv venv
python3 -mvenv venv
pyvenv-3.5 venv
source venv/bin/activate
cd venv
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig
curl -L https://cairographics.org/releases/pycairo-1.10.0.tar.bz2 | tar xj
cd pycairo-1.10.0
export ARCHFLAGS='-arch x86_64'
python waf configure --prefix=$VIRTUAL_ENV # It's ok, this will fail.
sed -i '' '154s/data={}/return/' .waf3-1.6.4-*/waflib/Build.py # Bugfix: https://bugs.freedesktop.org/show_bug.cgi?id=76759
python waf configure --prefix=$VIRTUAL_ENV # Now it should configure.
python waf build
python waf install
unset ARCHFLAGS
cd ..
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig
curl -L http://ftp.gnome.org/pub/GNOME/sources/pygobject/3.12/pygobject-3.12.2.tar.xz | tar xJ
cd pygobject-3.12.2
./configure CFLAGS="-I$VIRTUAL_ENV/include" --prefix=$VIRTUAL_ENV
make
make install
cd ..
安装pygobject
(pycairo
应作为依赖项提供)
原始答案
这就是我在OSX10.11上的Python3.5虚拟环境中获得GTK+3所做的
安装GTK+3(带)
创建并激活虚拟环境
python3 -mvenv venv
python3 -mvenv venv
pyvenv-3.5 venv
source venv/bin/activate
cd venv
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig
curl -L https://cairographics.org/releases/pycairo-1.10.0.tar.bz2 | tar xj
cd pycairo-1.10.0
export ARCHFLAGS='-arch x86_64'
python waf configure --prefix=$VIRTUAL_ENV # It's ok, this will fail.
sed -i '' '154s/data={}/return/' .waf3-1.6.4-*/waflib/Build.py # Bugfix: https://bugs.freedesktop.org/show_bug.cgi?id=76759
python waf configure --prefix=$VIRTUAL_ENV # Now it should configure.
python waf build
python waf install
unset ARCHFLAGS
cd ..
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig
curl -L http://ftp.gnome.org/pub/GNOME/sources/pygobject/3.12/pygobject-3.12.2.tar.xz | tar xJ
cd pygobject-3.12.2
./configure CFLAGS="-I$VIRTUAL_ENV/include" --prefix=$VIRTUAL_ENV
make
make install
cd ..
在虚拟环境中安装
python3 -mvenv venv
python3 -mvenv venv
pyvenv-3.5 venv
source venv/bin/activate
cd venv
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig
curl -L https://cairographics.org/releases/pycairo-1.10.0.tar.bz2 | tar xj
cd pycairo-1.10.0
export ARCHFLAGS='-arch x86_64'
python waf configure --prefix=$VIRTUAL_ENV # It's ok, this will fail.
sed -i '' '154s/data={}/return/' .waf3-1.6.4-*/waflib/Build.py # Bugfix: https://bugs.freedesktop.org/show_bug.cgi?id=76759
python waf configure --prefix=$VIRTUAL_ENV # Now it should configure.
python waf build
python waf install
unset ARCHFLAGS
cd ..
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig
curl -L http://ftp.gnome.org/pub/GNOME/sources/pygobject/3.12/pygobject-3.12.2.tar.xz | tar xJ
cd pygobject-3.12.2
./configure CFLAGS="-I$VIRTUAL_ENV/include" --prefix=$VIRTUAL_ENV
make
make install
cd ..
在虚拟环境中安装
python3 -mvenv venv
python3 -mvenv venv
pyvenv-3.5 venv
source venv/bin/activate
cd venv
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig
curl -L https://cairographics.org/releases/pycairo-1.10.0.tar.bz2 | tar xj
cd pycairo-1.10.0
export ARCHFLAGS='-arch x86_64'
python waf configure --prefix=$VIRTUAL_ENV # It's ok, this will fail.
sed -i '' '154s/data={}/return/' .waf3-1.6.4-*/waflib/Build.py # Bugfix: https://bugs.freedesktop.org/show_bug.cgi?id=76759
python waf configure --prefix=$VIRTUAL_ENV # Now it should configure.
python waf build
python waf install
unset ARCHFLAGS
cd ..
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig
curl -L http://ftp.gnome.org/pub/GNOME/sources/pygobject/3.12/pygobject-3.12.2.tar.xz | tar xJ
cd pygobject-3.12.2
./configure CFLAGS="-I$VIRTUAL_ENV/include" --prefix=$VIRTUAL_ENV
make
make install
cd ..
利润
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from gi.repository import Gtk, Gdk, Pango, GObject
>>> from cairo import ImageSurface, Context, FORMAT_ARGB32
>>>
Python3.5从下载并安装。现在可以使用解决此问题。Vext允许您在virtualenv中安装软件包,这些软件包可以单独访问您的系统软件包。要访问gi
,请执行以下操作:
pip install vext
pip install vext.gi
pip软件包的名称有点违反直觉-在Ubuntu(在19.04中测试)上使用pip安装PyGObject
,您可以下载软件包,然后按如下方式安装:
apt-get -y download python3-gi
dpkg-deb -x <package>.deb <virtualenv path>
apt get-y下载python3-gi
dpkg deb-x.deb
在Ubuntu中,下载包的名称是python3-gi_3.32.0-1_amd64.deb
当创建虚拟环境时,添加标志--系统站点包
感谢这个拉法,今天就要尝试这个。我刚刚尝试了这个拉法,这个对我来说非常有效,我看到了一个打字错误。sed-i''154s/data={}/return/'.waf3-1.6.4-*/waflib/Build.py应该是sed-i'154s/data={}/return/'.waf3-1.6.4-*/waflib/Build.py其他一切都很好,谢谢!嘿,马尔科姆,这不是打字错误。带有空字符串的-i
选项告诉OSX附带的标准sed
在不创建备份的情况下对文件执行内联替换。也许你使用的是sed
的GNU实现?嘘,就是这样,我已经安装了GNU-sed!再次感谢!!这样做之后,我仍然没有得到名为gi的模块
@bluppfisk:您仍然需要sudo安装pythongi
。据我所知,vext
只提供对gi
系统库的可见性,这是不正确的。在Ubuntu18上,在Python3.7VirtualEnv中,我仍然得到ImportError:没有名为gi的模块
。在Mac中它对我有效。ImportError:无法从“gi”中导入名称“\u gi”