簡體   English   中英

在pyenv中安裝PyQt5創建虛擬環境

[英]Installing PyQt5 in pyenv created virtual envirionment

我目前正在努力在虛擬環境中安裝 python package。 設置如下:我有一個 M1 mac,我在/usr/bin/python (v 2.7.18) 和usr/bin/python3 (v 3.8.9) 中安裝了系統 python。 因為我不太喜歡弄亂這些,所以我在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 

(大部分是按照 pyenv 的github 頁面上的解釋完成的)。

我現在正在嘗試在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 做好准備)並且還嘗試安裝舊版本( 5.14.1/2/, 5.15.0/1/2/3/4/5/6 ) of PyQt5通過命令

❯ 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'

如您所見,仍然沒有運氣......

可能您需要按照建議將 pip 升級到最新版本:

pip install --upgrade pip

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

編輯: Python 3.10尚不支持,如您所見:

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

並嘗試不同版本的PyQt ,您可以為 Python 3.9 嘗試5.14.0嗎?

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

正如 LemurPwned 在How can I run pyqt5 on my Mac with M1chip (ppc64el architecture) 中所說的那樣?

pyqt6 現在可以通過 pip 在 M1/M2 Mac 上輕松安裝

您可以通過 $pip install pyqt6 安裝它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM