尝试让 PyQt5 与 Pycharm 一起使用时出现错误和问题

Posted

技术标签:

【中文标题】尝试让 PyQt5 与 Pycharm 一起使用时出现错误和问题【英文标题】:Error and issues while attempting to get PyQt5 to work with Pycharm 【发布时间】:2020-04-02 21:22:42 【问题描述】:

我想将 PyQt5 与 pycharm 一起使用,

我第一次做pip install PyQt5pip install PyQt5-tools 他们安装正确(我认为)

但是当试图import PyQt5 pycharm 只是说它未解决。 然后我尝试转到 Pycharm > 设置 > Project Interpeter > 单击加号并尝试安装“PyQt5”,然后它因错误而停止,首先是我没有最新版本的 Microsoft Visual C++,(我做了) 但后来我安装了 microsoft 可视化构建工具并再次尝试,现在它出现了一个不同的错误: error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.25.28610\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2

这是命令输出:

  Using cached https://files.pythonhosted.org/packages/30/eb/99720998026e8c021c269c175cc80590c98293e1006323c2de9a8741c19d/PyQt5-5.14.1-5.14.1-cp35.cp36.cp37.cp38-none-win32.whl
Collecting PyQt5-sip<13,>=12.7 (from PyQt5)
  Using cached https://files.pythonhosted.org/packages/2c/fa/2c4c90bd328709129aae93a0bb15029982b6b5a3a2709679fca45bb7ee3b/PyQt5_sip-12.7.1.tar.gz
  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 wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Building wheels for collected packages: PyQt5-sip
  Building wheel for PyQt5-sip (PEP 517): started
  Building wheel for PyQt5-sip (PEP 517): finished with status 'error'
  Complete output from command C:\Users\info\PycharmProjects\PointsCalculator\venv\Scripts\python.exe C:\Users\info\PycharmProjects\PointsCalculator\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\pep517\_in_process.py build_wheel C:\Users\info\AppData\Local\Temp\tmpqjlmpyqz:
  running bdist_wheel
  running build
  running build_ext
  building 'PyQt5.sip' extension
  creating build
  creating build\temp.win32-3.8
  creating build\temp.win32-3.8\Release
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\info\PycharmProjects\PointsCalculator\venv\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\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" /Tcapiversions.c /Fobuild\temp.win32-3.8\Release\apiversions.obj
  apiversions.c
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\info\PycharmProjects\PointsCalculator\venv\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\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" /Tcarray.c /Fobuild\temp.win32-3.8\Release\array.obj
  array.c
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\info\PycharmProjects\PointsCalculator\venv\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\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" /Tcdescriptors.c /Fobuild\temp.win32-3.8\Release\descriptors.obj
  descriptors.c
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\info\PycharmProjects\PointsCalculator\venv\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\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" /Tcint_convertors.c /Fobuild\temp.win32-3.8\Release\int_convertors.obj
  int_convertors.c
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\info\PycharmProjects\PointsCalculator\venv\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\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" /Tcobjmap.c /Fobuild\temp.win32-3.8\Release\objmap.obj
  objmap.c
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\info\PycharmProjects\PointsCalculator\venv\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\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" /Tcqtlib.c /Fobuild\temp.win32-3.8\Release\qtlib.obj
  qtlib.c
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\info\PycharmProjects\PointsCalculator\venv\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\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" /Tcsiplib.c /Fobuild\temp.win32-3.8\Release\siplib.obj
  siplib.c
  siplib.c(2902): warning C4013: 'sipSetBool' undefined; assuming extern returning int
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\info\PycharmProjects\PointsCalculator\venv\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\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" /Tcthreads.c /Fobuild\temp.win32-3.8\Release\threads.obj
  threads.c
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\info\PycharmProjects\PointsCalculator\venv\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\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" /Tcvoidptr.c /Fobuild\temp.win32-3.8\Release\voidptr.obj
  voidptr.c
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\info\PycharmProjects\PointsCalculator\venv\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\info\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\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" /EHsc /Tpbool.cpp /Fobuild\temp.win32-3.8\Release\bool.obj
  bool.cpp
  c1xx: fatal error C1083: Cannot open source file: 'bool.cpp': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.25.28610\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2

  ----------------------------------------
  Running setup.py clean for PyQt5-sip
Failed to build PyQt5-sip

  Failed building wheel for PyQt5-sip
Could not build wheels for PyQt5-sip which use PEP 517 and cannot be installed directly

我不知道还能尝试什么

【问题讨论】:

【参考方案1】:

修复错误,进入pycharm目录,在packages中找到PyQt5文件夹并删除,然后将pip新建的PyQt5包复制到python包目录中

【讨论】:

以上是关于尝试让 PyQt5 与 Pycharm 一起使用时出现错误和问题的主要内容,如果未能解决你的问题,请参考以下文章

将 QML 中的 QSortFilterProxyModel 与 PyQt5 一起使用

pyqt 与 Anaconda 一起安装时找不到 PyQt5.QtWidgets 模块

PyCharm中安装与使用PyQt5

Pyinstaller 的 PyQT5 QFileDialog 问题

PyQt5系列教程如何让界面和逻辑分离

PyCharm集成PyQt5以及使用