【问题标题】:Installing PyQt5 in pyenv created virtual envirionment在pyenv中安装PyQt5 创建虚拟环境
【发布时间】:2022-01-10 09:39:35
【问题描述】:

我目前正在努力在虚拟环境中安装 python 包。设置如下:我有一个 M1 mac,我的系统 python 安装位于 /usr/bin/python (v 2.7.18) 和 usr/bin/python3 (v 3.8.9)。因为我不太喜欢搞这些,所以我在brew 上安装了pyenvpyenv-virtualenv。我安装了 Python 3.10.1 并创建了一个虚拟环境,我们称之为test。我还在.zshrc中添加了以下几行

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'
PATH=$(pyenv root)/shims:$PATH 

(大部分都是按照github page of pyenv上的说明完成的)。

我现在正尝试在test 中安装一些软件包。 numpy, scipy 等运行良好,但是当我尝试使用 pip 安装 PyQt5 时出现错误。

❯ pip install PyQt5
Collecting PyQt5
  Using cached PyQt5-5.15.6.tar.gz (3.2 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/UserName/.pyenv/versions/3.10.1/envs/simpy/bin/python3.10 /Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/tmp2ofsepfy
       cwd: /private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-install-5rev2dd7/pyqt5_3892c9f35c2f41a186bcd36237d536d7
  Complete output (29 lines):
  Traceback (most recent call last):
    File "/Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 156, in prepare_metadata_for_build_wheel
      hook = backend.prepare_metadata_for_build_wheel
  AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
      main()
    File "/Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 160, in prepare_metadata_for_build_wheel
      whl_basename = backend.build_wheel(metadata_directory, config_settings)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/sipbuild/api.py", line 51, in build_wheel
      project = AbstractProject.bootstrap('pep517')
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
      project.setup(pyproject, tool, tool_description)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/sipbuild/project.py", line 587, in setup
      self.apply_user_defaults(tool)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-install-5rev2dd7/pyqt5_3892c9f35c2f41a186bcd36237d536d7/project.py", line 63, in apply_user_defaults
      super().apply_user_defaults(tool)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
      super().apply_user_defaults(tool)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/sipbuild/project.py", line 234, in apply_user_defaults
      self.builder.apply_user_defaults(tool)
    File "/private/var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/pip-build-env-vyb7aqa6/overlay/lib/python3.10/site-packages/pyqtbuild/builder.py", line 67, in apply_user_defaults
      raise PyProjectOptionException('qmake',
  sipbuild.pyproject.PyProjectOptionException
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/3b/27/fd81188a35f37be9b3b4c2db1654d9439d1418823916fe702ac3658c9c41/PyQt5-5.15.6.tar.gz#sha256=80343bcab95ffba619f2ed2467fd828ffeb0a251ad7225be5fc06dcc333af452 (from https://pypi.org/simple/pyqt5/) (requires-python:>=3.6). Command errored out with exit status 1: /Users/UserName/.pyenv/versions/3.10.1/envs/simpy/bin/python3.10 /Users/UserName/.pyenv/versions/3.10.1/envs/simpy/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/yk/q1gxptj56gj5n3jt8l48xj580000gn/T/tmp2ofsepfy Check the logs for full command output.

这里到底发生了什么?这与m1芯片或虚拟环境的设置有关吗?我该如何解决这个问题?


根据@pedro_bb7 的建议,我将 Python 降级到 3.9.9(因为 PyQt5 还没有为 Python 3.10.0 做好准备)并且还尝试通过命令安装 PyQt5 的旧版本(5.14.1/2/, 5.15.0/1/2/3/4/5/6

❯ pip install PyQt5==5.14.0
Collecting PyQt5==5.14.0
  Using cached PyQt5-5.14.0.tar.gz (3.2 MB)
ERROR: PyQt5==5.14.0 from https://files.pythonhosted.org/packages/7c/5b/e760ec4f868cb77cee45b4554bf15d3fe6972176e89c4e3faac941213694/PyQt5-5.14.0.tar.gz#sha256=0145a6b7de15756366decb736c349a0cb510d706c83fda5b8cd9e0557bc1da72 has a pyproject.toml file that does not comply with PEP 518: 'build-system.requires' contains an invalid requirement: 'sip >=5.0.1 <6'

如您所见,仍然没有运气......

【问题讨论】:

    标签: python pyqt5 apple-m1 python-venv pyvenv


    【解决方案1】:

    您可能需要按照建议将 pip 升级到最新版本:

    pip install --upgrade pip
    

    https://stackoverflow.com/a/67606704/11381650

    编辑: 如您所见,Python 3.10 尚不支持:

    https://github.com/altendky/pyqt-tools/issues/98

    并尝试不同版本的PyQt,您能否尝试5.14.0 for Python 3.9?

    https://stackoverflow.com/a/59797479/11381650

    【讨论】:

    • 已经完成但无法正常工作。 Pip 版本为 21.3.1
    • PyQt 版本怎么样?也许你需要指定一个适用于你正在使用的 Python 版本..
    • 我刚刚用 Python 3.9.9 尝试过,我得到了同样的错误......
    • 试过 5.14.1/2/、5.15.0/1/2/3/4/5/6 都不起作用。错误信息可以在here找到。
    • @morejanus 不,不是。您可以在homebrew 上安装PyQt5,并且应该能够与/opt/homebrew/bin/python3 一起使用它。但我仍然无法让它在虚拟环境中运行。
    猜你喜欢
    • 1970-01-01
    • 2016-01-10
    • 1970-01-01
    • 2019-05-16
    • 2021-04-21
    • 2014-02-26
    • 2021-06-03
    • 2020-02-03
    • 1970-01-01
    相关资源
    最近更新 更多