Is it possible to require PyQt from setuptools setup.py?

前端 未结 4 761
梦如初夏
梦如初夏 2020-12-03 08:13

I\'m building a small app that uses PyQt and tought it\'d be nice to declare that dependency in setup.py.

However, according to this blog (first hit on google for p

相关标签:
4条回答
  • 2020-12-03 08:30

    While the accepted answer was originally correct Python Wheels now provide a means to install C extension packages such as PyQt5 without the need for compilation from source.

    PyPi currently has .whl files for PyQt5 on Python3 for multiple platforms, including MacOS X, Linux (any), Win32 and Win64. For example, this is the output when pip-installing PyQt5 on Python3 on a Mac:

    mfitzp@MacBook-Air ~ $ pip3 install pyqt5
    Collecting pyqt5
      Downloading PyQt5-5.6-cp35-cp35m-macosx_10_6_intel.whl (73.2MB)
        100% |████████████████████████████████| 73.2MB 2.5kB/s 
    Collecting sip (from pyqt5)
      Downloading sip-4.18-cp35-cp35m-macosx_10_6_intel.whl (46kB)
        100% |████████████████████████████████| 49kB 1.8MB/s 
    Installing collected packages: sip, pyqt5
    Successfully installed pyqt5-5.6 sip-4.18
    

    If you are targeting Python3+PyQt5 then you should have no problem specifying PyQt5 as a normal dependency in setup.py.

    0 讨论(0)
  • 2020-12-03 08:31

    Right, the PyQT packages are not using distutils / setup.py for it's installation, so they can't be installed with easy_install or pip. You need to download and install it manually.

    That also means you should not put it in your requires metadata, as easy_install and pip then will try to install it and fail.

    I don't know if PySide is any good, but is also has not setup.py, and also refuse to install with easy_install/pip, so not a good option. :)

    Another option is to repackage PyQt with distutils, but that may be a lot of work.

    0 讨论(0)
  • 2020-12-03 08:45

    Setuptools >= 38.2.0 now knows how to install wheels. The trivial answer, therefore, is to install a recent version of setuptools and require that your enlightened userbase does so as well. To enforce usage of setuptools >= 38.2.0 at installation time, see this relevant answer elsewhere.

    Since setuptools 38.2.0 was released over a year ago, all prior answers to this question are horrifyingly obsolete, blatantly wrong, and less than useful.

    0 讨论(0)
  • 2020-12-03 08:46

    While you can pip install pyqt5 thanks to the now available wheels (as suggested by @mfitzp), it cannot be required from setup.py via install_requires. The reason is that setuptools doesn't know how to install wheels which pip knows how to, and PyQT5 is only available as wheels on PyPI (there is no source distribution, i.e. no tar.gz file). See this email and that bug report for details.

    0 讨论(0)
提交回复
热议问题