python setup.py-安装后如何显示消息

eri*_*i0o 5 python setup.py python-3.x

我正在开发一个PyQt5应用程序,并使其可用,pip install因为python3中的pip可以将pyqt5安装为依赖项。我创建了一个启动包的入口,并告诉setup.py这是一个gui_scripts。

我现在想做的是,在该人键入pip install package并完成安装之后,向该人显示一条消息,告诉您现在可以package在终端中键入以加载应用程序。正确的做法是什么?还是我不应该这样做?

Jos*_*ras 5

如果你能确保

  • 该软件包总是从源代码分发版安装,而不是二进制轮,并且
  • 用户使用-v选项pip install,

您可以在setup.py脚本中输出文本。

这setup.py几乎是一个常规的 Python 脚本。只需使用文件print()末尾的函数即可setup.py。在这个例子中,文件结构是somedir/setup.py,somedir/test/和test/__init__.py。

简单的解决方案

from setuptools import setup

print("Started!")

setup(name='testing',
      version='0.1',
      description='The simplest setup in the world',
      classifiers=[
        'Development Status :: 3 - Alpha',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3.0',
      ],
      keywords='setup',
      author='someone',
      author_email='someone@example.com',
      license='MIT',
      packages=['test'],
      entry_points={
      },
      zip_safe=False)

print("Finished!")
Run Code Online (Sandbox Code Playgroud)

开始了!
running install
running bdist_egg
running egg_info
编写 testing.egg-info/PKG-INFO
...
...
...
处理测试依赖== 0.1
处理测试依赖== 0.1
完成!

使用setuptools.command.install溶液

此外,您可以对setuptools.command.install命令进行子类化。检查差异,当你改变的顺序install.run(self)和os.system("cat testing.egg-info/PKG-INFO")在一个干净的安装。

from setuptools import setup
from setuptools.command.install import install
import os


class PostInstallCommand(install):
    """Post-installation for installation mode."""
    def run(self):
        install.run(self)
        os.system("cat testing.egg-info/PKG-INFO")


setup(name='testing',
      version='0.1',
      description='The simplest setup in the world',
      classifiers=[
        'Development Status :: 3 - Alpha',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3.0',
      ],
      keywords='setup',
      author='someone',
      author_email='someone@example.com',
      license='MIT',
      packages=['test'],
      entry_points={
      },
      cmdclass={
        'install': PostInstallCommand,
      },
      zip_safe=False)
Run Code Online (Sandbox Code Playgroud)

  • 令人讨厌的是,*pip* 会吞噬这些自定义消息,除非您使用 *-v* 或其他方式运行它。任务有效,但您只是看不到消息。 (22认同)
  • 另外,我还没有找到一种方法可以使用 pip 安装轮来完成这项工作。它们在安装时不会“运行”“setup.py”——仅在打包成“.whl”时才运行。 (2认同)