1

https://github.com/cztomczak/cefpython/blob/master/src/linux/binaries_64bit/kivy_.py中,pygtk并被gtk使用。(注意源代码只在Linux下测试过,我用的是Windows)

当我尝试时pip install pygtk,出现错误

Collecting pygtk
  Using cached pygtk-2.24.0.tar.bz2 (2.4 MB)
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\jared\appdata\local\programs\python\python37\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\jared\\AppData\\Local\\Temp\\pip-install-rle_vbsd\\pygtk\\setup.py'"'"'; __file__='"'"'C:\\Users\\jared\\AppData\\Local\\Temp\\pip-install-rle_vbsd\\pygtk\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\jared\AppData\Local\Temp\pip-pip-egg-info-pex79haa'
         cwd: C:\Users\jared\AppData\Local\Temp\pip-install-rle_vbsd\pygtk\
    Complete output (1 lines):
    ERROR: Could not import dsextras module: Make sure you have installed pygobject.
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

因此,我又去了pip install pygobject,错误。

Collecting pygobject
  Using cached PyGObject-3.38.0.tar.gz (712 kB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\jared\appdata\local\programs\python\python37\python.exe' 'c:\users\jared\appdata\local\programs\python\python37\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'C:\Users\jared\AppData\Local\Temp\pip-build-env-t_0q3g_h\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel pycairo
       cwd: None
  Complete output (34 lines):
  Collecting setuptools
    Using cached setuptools-50.3.0-py3-none-any.whl (785 kB)
  Collecting wheel
    Using cached wheel-0.35.1-py2.py3-none-any.whl (33 kB)
  Collecting pycairo
    Using cached pycairo-1.19.1.tar.gz (205 kB)
  Using legacy 'setup.py install' for pycairo, since package 'wheel' is not installed.
  Installing collected packages: setuptools, wheel, pycairo
      Running setup.py install for pycairo: started
      Running setup.py install for pycairo: finished with status 'error'
      ERROR: Command errored out with exit status 1:
       command: 'c:\users\jared\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\jared\\AppData\\Local\\Temp\\pip-install-faiuku8y\\pycairo\\setup.py'"'"'; __file__='"'"'C:\\Users\\jared\\AppData\\Local\\Temp\\pip-install-faiuku8y\\pycairo\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\jared\AppData\Local\Temp\pip-record-kq9tlvv8\install-record.txt' --single-version-externally-managed --prefix 'C:\Users\jared\AppData\Local\Temp\pip-build-env-t_0q3g_h\overlay' --compile --install-headers 'C:\Users\jared\AppData\Local\Temp\pip-build-env-t_0q3g_h\overlay\Include\pycairo'
           cwd: C:\Users\jared\AppData\Local\Temp\pip-install-faiuku8y\pycairo\
      Complete output (18 lines):
      running install
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.7
      creating build\lib.win-amd64-3.7\cairo
      copying cairo\__init__.py -> build\lib.win-amd64-3.7\cairo
      copying cairo\__init__.pyi -> build\lib.win-amd64-3.7\cairo
      copying cairo\py.typed -> build\lib.win-amd64-3.7\cairo
      running build_ext
      building 'cairo._cairo' extension
      creating build\temp.win-amd64-3.7
      creating build\temp.win-amd64-3.7\Release
      creating build\temp.win-amd64-3.7\Release\cairo
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DPYCAIRO_VERSION_MAJOR=1 -DPYCAIRO_VERSION_MINOR=19 -DPYCAIRO_VERSION_MICRO=1 -Ic:\users\jared\appdata\local\programs\python\python37\include -Ic:\users\jared\appdata\local\programs\python\python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /Tccairo/device.c /Fobuild\temp.win-amd64-3.7\Release\cairo/device.obj
      device.c
      C:\Users\jared\AppData\Local\Temp\pip-install-faiuku8y\pycairo\cairo\pycairo.h(37): fatal error C1083: Cannot open include file: 'cairo.h': No such file or directory
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
      ----------------------------------------
  ERROR: Command errored out with exit status 1: 'c:\users\jared\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\jared\\AppData\\Local\\Temp\\pip-install-faiuku8y\\pycairo\\setup.py'"'"'; __file__='"'"'C:\\Users\\jared\\AppData\\Local\\Temp\\pip-install-faiuku8y\\pycairo\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\jared\AppData\Local\Temp\pip-record-kq9tlvv8\install-record.txt' --single-version-externally-managed --prefix 'C:\Users\jared\AppData\Local\Temp\pip-build-env-t_0q3g_h\overlay' --compile --install-headers 'C:\Users\jared\AppData\Local\Temp\pip-build-env-t_0q3g_h\overlay\Include\pycairo' Check the logs for full command output.
  ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\jared\appdata\local\programs\python\python37\python.exe' 'c:\users\jared\appdata\local\programs\python\python37\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'C:\Users\jared\AppData\Local\Temp\pip-build-env-t_0q3g_h\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel pycairo Check the logs for full command output.

然后我参考了一些关于 stackoverflow 的帖子,他们告诉我gtk不再需要它,python3并将其替换为pgi. (我不知道我应该在源代码中替换pygtkor gtk)所以我尝试了pip install pgi,再次出错。

Collecting pgi
  Using cached pgi-0.0.11.2.tar.gz (239 kB)
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\jared\appdata\local\programs\python\python37\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\jared\\AppData\\Local\\Temp\\pip-install-2znm3fjc\\pgi\\setup.py'"'"'; __file__='"'"'C:\\Users\\jared\\AppData\\Local\\Temp\\pip-install-2znm3fjc\\pgi\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\jared\AppData\Local\Temp\pip-pip-egg-info-5e57ceft'
         cwd: C:\Users\jared\AppData\Local\Temp\pip-install-2znm3fjc\pgi\
    Complete output (21 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\jared\AppData\Local\Temp\pip-install-2znm3fjc\pgi\setup.py", line 18, in <module>
        import pgi
      File "C:\Users\jared\AppData\Local\Temp\pip-install-2znm3fjc\pgi\pgi\__init__.py", line 10, in <module>
        from .importer import require_version, get_required_version
      File "C:\Users\jared\AppData\Local\Temp\pip-install-2znm3fjc\pgi\pgi\importer.py", line 15, in <module>
        from .clib.gir import GIRepository
      File "C:\Users\jared\AppData\Local\Temp\pip-install-2znm3fjc\pgi\pgi\clib\gir\__init__.py", line 8, in <module>
        from .giargument import GIArgument
      File "C:\Users\jared\AppData\Local\Temp\pip-install-2znm3fjc\pgi\pgi\clib\gir\giargument.py", line 9, in <module>
        from ..glib import gboolean, gint8, guint8, gint16, guint16, gint32, guint32
      File "C:\Users\jared\AppData\Local\Temp\pip-install-2znm3fjc\pgi\pgi\clib\glib.py", line 16, in <module>
        _glib = find_library("glib-2.0")
      File "C:\Users\jared\AppData\Local\Temp\pip-install-2znm3fjc\pgi\pgi\clib\_utils.py", line 99, in find_library
        _internal[name] = cdll.LoadLibrary(_so_mapping[name])
      File "c:\users\jared\appdata\local\programs\python\python37\lib\ctypes\__init__.py", line 442, in LoadLibrary
        return self._dlltype(name)
      File "c:\users\jared\appdata\local\programs\python\python37\lib\ctypes\__init__.py", line 364, in __init__
        self._handle = _dlopen(self._name, mode)
    OSError: [WinError 126] The specified module could not be found
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

我不知道发生了什么。我希望有人能把我从这个无限错误循环中拉出来。非常感谢。

4

1 回答 1

0

首先我要提一下我使用的是Xubuntu 20.04,所以是Linux。

为了使 kivy 示例正常工作,您需要将 pygtk 模块替换为 PyGobject 模块。所以安装它,这里是说明:

https://pygobject.readthedocs.io/en/latest/getting_started.html#windows-logo-windows

现在在这个文件中 https://github.com/cztomczak/cefpython/blob/master/src/linux/binaries_64bit/kivy_.py你需要更改导入和其他一些东西。这是我的进口商品的样子

...

from cefpython3 import cefpython as cef

import gi       # notice this line is added
# import pygtk  # this one is commented out or you can delete it
from gi.repository import Gtk as gtk    # this one is added
# import gtk    # this one is commented out or you can delete it
import sys

...

from kivy.graphics.texture import Texture
from kivy.uix.boxlayout import BoxLayout
from kivy.base import EventLoop

# Global variables
g_switches = None

# PyGTK required
# pygtk.require('2.0') # this one is commented out or you can delete it


class BrowserLayout(BoxLayout):
...

我还需要修复传递给windowInfo.SetAsOffscreen在第 208 行附近调用的方法的参数(在我的情况下),查找start_cef方法定义。我根据这个https://github.com/cztomczak/cefpython/blob/master/api/WindowInfo.md#setasoffscreen将参数设置为 0,因为它提到:

您可以将 0 作为 parentWindowHandle 传递,但是上下文菜单和插件等某些内容可能无法正确显示。

所以代码看起来像这样:

...
#popup widgets to work.
gtkwin = gtk.Window()
gtkwin.realize()

# WindowInfo offscreen flag
windowInfo = cef.WindowInfo()
windowInfo.SetAsOffscreen(0)
    
# Create Broswer and naviagte to empty page <= OnPaint won't get
# called yet
...
于 2020-09-25T15:46:28.877 回答