Pipenv不能安装PyQt5



我正在尝试在pipenv虚拟环境中安装以下软件包,但这在Mac M1中是不可能的。我还没有在其他电脑上试过

我已经使用了两个可能的包

选项1

[packages]
pyqt5-sip = "*"
pyqt5 = "*"

选项2

[packages]
pyqt5-sip = "==12.7.0"
pyqt5 = "==5.10.1". #This package doesn't seem to exist

我将张贴不同安装方法的不同错误

pipenv install

Pipfile.lock (7d18ff) out of date, updating to (bb5ccf)...
Locking [packages] dependencies...
Building requirements...
✘ Locking Failed! 
ERROR:pip.subprocessor:[present-rich] Preparing metadata (pyproject.toml) exited with 1
[ResolutionFailure]:   File "/opt/homebrew/Cellar/pipenv/2022.9.21/libexec/lib/python3.10/site-packages/pipenv/resolver.py", line 782, in _main
[ResolutionFailure]:       resolve_packages(
[ResolutionFailure]:   File "/opt/homebrew/Cellar/pipenv/2022.9.21/libexec/lib/python3.10/site-packages/pipenv/resolver.py", line 730, in resolve_packages
[ResolutionFailure]:       results, resolver = resolve(
[ResolutionFailure]:   File "/opt/homebrew/Cellar/pipenv/2022.9.21/libexec/lib/python3.10/site-packages/pipenv/resolver.py", line 709, in resolve
[ResolutionFailure]:       return resolve_deps(
[ResolutionFailure]:   File "/opt/homebrew/Cellar/pipenv/2022.9.21/libexec/lib/python3.10/site-packages/pipenv/utils/resolver.py", line 1105, in resolve_deps
[ResolutionFailure]:       results, hashes, markers_lookup, resolver, skipped = actually_resolve_deps(
[ResolutionFailure]:   File "/opt/homebrew/Cellar/pipenv/2022.9.21/libexec/lib/python3.10/site-packages/pipenv/utils/resolver.py", line 894, in actually_resolve_deps
[ResolutionFailure]:       resolver.resolve()
[ResolutionFailure]:   File "/opt/homebrew/Cellar/pipenv/2022.9.21/libexec/lib/python3.10/site-packages/pipenv/utils/resolver.py", line 689, in resolve
[ResolutionFailure]:       raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
You can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: metadata generation failed

pipenv install --skip-lock

Installing dependencies from Pipfile...
An error occurred while installing pyqt5-sip! Will try again.
An error occurred while installing pyqt5! Will try again.
Installing initially failed dependencies...
Failed to install some dependency or packages.  The following have failed installation and attempted retry: [Requirement(_name='pyqt5-sip', vcs=None, req=NamedRequirement(name='pyqt5-sip', version='', req=Requirement.parse('pyqt5-sip'), extras=[], editable=False, _parsed_line=<Line (editable=False, name=pyqt5-sip, path=None, uri=None, extras=(), markers=None, vcs=None, specifier=None, pyproject=None, pyproject_requires=None, pyproject_backend=None, ireq=pyqt5-sip)>), markers=None, _specifiers='', index=None, editable=False, hashes=frozenset(), extras=(), abstract_dep=None, _line_instance=<Line (editable=False, name=pyqt5-sip, path=None, uri=None, extras=(), markers=None, vcs=None, specifier=None, pyproject=None, pyproject_requires=None, pyproject_backend=None, ireq=pyqt5-sip)>, _ireq=None), Requirement(_name='pyqt5', vcs=None, req=NamedRequirement(name='pyqt5', version='', req=Requirement.parse('pyqt5'), extras=[], editable=False, _parsed_line=<Line (editable=False, name=pyqt5, path=None, uri=None, extras=(), markers=None, vcs=None, specifier=None, pyproject=None, pyproject_requires=None, pyproject_backend=None, ireq=pyqt5)>), markers=None, _specifiers='', index=None, editable=False, hashes=frozenset(), extras=(), abstract_dep=None, _line_instance=<Line (editable=False, name=pyqt5, path=None, uri=None, extras=(), markers=None, vcs=None, specifier=None, pyproject=None, pyproject_requires=None, pyproject_backend=None, ireq=pyqt5)>, _ireq=None)]

pipenv install pyqt5

Installing pyqt5...
Error:  An error occurred while installing pyqt5!
Error text: Collecting pyqt5
Using cached PyQt5-5.15.7.tar.gz (3.2 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'error'
error: subprocess-exited-with-error

× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [29 lines of output]
Traceback (most recent call last):
File "/opt/homebrew/Cellar/pipenv/2022.9.21/libexec/lib/python3.10/site-packages/pipenv/patched/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 "/opt/homebrew/Cellar/pipenv/2022.9.21/libexec/lib/python3.10/site-packages/pipenv/patched/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/opt/homebrew/Cellar/pipenv/2022.9.21/libexec/lib/python3.10/site-packages/pipenv/patched/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/opt/homebrew/Cellar/pipenv/2022.9.21/libexec/lib/python3.10/site-packages/pipenv/patched/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/z8/lhf1yvnd1tb1bvq856nr_0240000gn/T/pip-build-env-t831aefc/overlay/lib/python3.9/site-packages/sipbuild/api.py", line 46, in build_wheel
project = AbstractProject.bootstrap('wheel',
File "/private/var/folders/z8/lhf1yvnd1tb1bvq856nr_0240000gn/T/pip-build-env-t831aefc/overlay/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 87, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/private/var/folders/z8/lhf1yvnd1tb1bvq856nr_0240000gn/T/pip-build-env-t831aefc/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 585, in setup
self.apply_user_defaults(tool)
File "project.py", line 69, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/z8/lhf1yvnd1tb1bvq856nr_0240000gn/T/pip-build-env-t831aefc/overlay/lib/python3.9/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/z8/lhf1yvnd1tb1bvq856nr_0240000gn/T/pip-build-env-t831aefc/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 236, in apply_user_defaults
self.builder.apply_user_defaults(tool)
File "/private/var/folders/z8/lhf1yvnd1tb1bvq856nr_0240000gn/T/pip-build-env-t831aefc/overlay/lib/python3.9/site-packages/pyqtbuild/builder.py", line 69, in apply_user_defaults
raise PyProjectOptionException('qmake',
sipbuild.pyproject.PyProjectOptionException
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
✘ Installation Failed 

背景故事

下面的步骤肯定对在Apple Mac M1机器上使pipenvpyqt5一起工作很有帮助。

很大一部分原因是我忽略了使用pip而不是pipenv命令来接受许可条款。这是一个巨大的浪费时间,因为pipenv将被卡住长达一个小时在显示失败之前,更糟糕的是,当您运行没有--verbose标志的pipenv install时,您不会看到由于许可条款而导致的错误。

<<p>步骤/strong>
  1. 确保您已经成功地从homebrew安装了pyqt5:

    brew install pyqt@5

  2. 在文本编辑器中打开~/.zshrc并添加以下行:

    export PATH="/opt/homebrew/opt/qt5/bin:$PATH"
    

    您可能需要根据您的自制brew安装文件夹调整路径。如果您不确定,您可以运行brew --prefix qt5来查找确切的路径

  3. 打开一个新的终端在现有终端输入:

    source ~/.zshrc
    
  4. 进入Python项目文件夹,输入:

    pipenv shell
    pip install pyqt5 --config-settings --confirm-license= --verbose
    
  5. 拿一杯咖啡,等待步骤4完成,这将花费一些时间,但是如果您使用'——verbose'命令运行,您应该很快(不到一分钟)看到日志:

    Querying qmake about your Qt installation...
    This is the GPL version of PyQt 5.15.9 (licensed under the GNU General  Public License) for Python 3.11.3 on darwin.
    Found the license file 'pyqt-gpl.sip'.
    Checking to see if the QtCore bindings can be built...
    

    这是一个好消息,这意味着至少你的安装不会因为许可证而卡住,如果你要运行pipenv

    如果你足够幸运,在大约10-15分钟后,你会看到:

    Successfully installed pyqt5-5.15.9
    

在简介:

诀窍是在虚拟环境中使用pipinstall而不是pipenvinstall(先运行pipenv shell)