【问题标题】:Python cannot install PyGObjectPython 无法安装 PyGObject
【发布时间】:2016-02-25 00:40:58
【问题描述】:

我尝试通过 pip 安装 pygobject

pip install --user PyGObject

但我不工作:

Collecting PyGObject
  Using cached pygobject-2.28.3.tar.bz2
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "C:\Users\A\AppData\Local\Temp\pip-build-phby_jwb\PyGObject\
setup.py", line 272
        raise SystemExit, 'ERROR: Nothing to do, gio could not be found and is
 essential.'
                        ^
    SyntaxError: invalid syntax

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\A\AppData\Local\Temp\pip-build-phby_jwb\PyGObject

我的python版本v3.5.0:374f501f4567, 现在我在 Windows 7 上工作

【问题讨论】:

    标签: python windows python-3.x pip pygobject


    【解决方案1】:

    2017年2月起,可以直接通过pip安装pygobject:pip install pygobject。但它需要安装一些软件包。

    在此之前,花了一段时间,但可以使用 pip 安装 pygobject,因为 this commit

    pygobject 不在 pypi 上,所以你必须指定 git 或 tarball URL:

    • git+https://git.gnome.org/browse/pygobject
    • https://download.gnome.org/sources/pygobject/3.22/pygobject-3.22.0.tar.xz

    后者仅适用于 pygobject 3.22+,这应该发生在around mid-september 2016。 (3.21.1 应该是第一个可安装 pip 的开发版本)

    【讨论】:

    • 你指定的这两种方法我都试过了,还是不能安装!
    • 我收到一个错误提示“错误:[WinError 193] %1 不是有效的 Win32 应用程序”
    【解决方案2】:

    对于窗户

    1. 转到 http://www.msys2.org/ 并下载 x86_64 安装程序
    2. 按照页面上的说明设置基本环境
    3. 运行C:\msys64\mingw32.exe - 应该会弹出一个终端窗口
    4. 执行pacman -Suy
    5. 执行pacman -S mingw-w64-i686-gtk3 mingw-w64-i686-python3-gobject
    6. 要测试 GTK 3 是否正常工作,您可以运行 gtk3-demo
    7. 将您创建的hello.py 脚​​本复制到C:\msys64\home\&lt;username&gt;
    8. 在 mingw32 终端中执行 python3 hello.py - 应该会出现一个窗口。

    对于 ubuntu / Debian

    安装系统提供的PyGObject

    1. 打开终端
    2. 执行sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0
    3. 将目录更改为可以找到hello.py 脚本的位置(例如cd Desktop
    4. 运行python3 hello.py

    使用 pip 从 PyPI 安装

    1. 打开终端并进入您的虚拟环境
    2. 执行
      sudo apt install libgirepository1.0-dev gcc libcairo2-dev pkg-config python3-dev gir1.2-gtk-3.0
    3. 执行pip3 install pycairo 构建和安装Pycairo
    4. 执行pip3 install PyGObject 构建和安装PyGObject
    5. 将工作目录更改为可以找到hello.py 脚本的位置
    6. 运行python3 hello.py

    您可以阅读更多here

    【讨论】:

      【解决方案3】:

      上游 PyGObject 只是不支持这一点。请参阅PyGObject win32 项目或MSYS2 项目以轻松获取。

      【讨论】:

        【解决方案4】:

        我将添加我一直在使用的东西,以便在各种项目中无缝地工作。

        它使用 GNU Make,通过提供一个venv 目标,可以将其用作对其他目标的依赖,以确保正确创建虚拟环境。

        venv 目标本身依赖于 requirements.txt,尽管是可配置的;标准 python 需求文件。

        一个目标test 被包含在内作为如何使用它的示例。

        诀窍是为已安装的系统包创建符号链接。 ln -s ${DIST_PACKAGES}/gi ${VENV_NAME}/lib/python${PYTHON_VER}/site-packages/gi,其中$DIST_PACKAGE 是您系统上安装的python 库的位置。

        对于那些不熟悉make的人。在项目的根目录下创建一个名为Makefile 的文件,复制下面的内容,然后发出命令make configure &amp;&amp; make venv

        生成文件

        # directory to store virtual environment
        VENV_NAME=venv
        
        # python runtime version
        PYTHON_VER=3.6
        
        # python executble
        PYTHON=${VENV_NAME}/bin/python${PYTHON_VER}
        
        # python local libraries location
        DIST_PACKAGES=/usr/lib/python3/dist-packages
        
        # pip requirements file
        REQUIREMENTS=requirements.txt
        
        configure:      ## Install required debian packages.
            sudo apt-get -y install python${PYTHON_VER} python3-pip libgirepository1.0-dev
            python3 -m pip install virtualenv pygobject
            make venv
        
        venv:           ## Recreates the virtual environment if needed.
        venv: $(VENV_NAME)/bin/activate
        $(VENV_NAME)/bin/activate: ${REQUIREMENTS}
            test -d $(VENV_NAME) || virtualenv -p python${PYTHON_VER} $(VENV_NAME)
            ${PYTHON} -m pip install -U pip
            ${PYTHON} -m pip install -r ${REQUIREMENTS}
            ln -s ${DIST_PACKAGES}/gi ${VENV_NAME}/lib/python${PYTHON_VER}/site-packages/gi
            touch $@
        
        test:           ## Runs the test suite.
        test: venv
            $(PYTHON) -m pytest tests
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-12-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多