• <tfoot id='yHQlD'></tfoot>
  • <legend id='yHQlD'><style id='yHQlD'><dir id='yHQlD'><q id='yHQlD'></q></dir></style></legend>

      <small id='yHQlD'></small><noframes id='yHQlD'>

        <bdo id='yHQlD'></bdo><ul id='yHQlD'></ul>
      <i id='yHQlD'><tr id='yHQlD'><dt id='yHQlD'><q id='yHQlD'><span id='yHQlD'><b id='yHQlD'><form id='yHQlD'><ins id='yHQlD'></ins><ul id='yHQlD'></ul><sub id='yHQlD'></sub></form><legend id='yHQlD'></legend><bdo id='yHQlD'><pre id='yHQlD'><center id='yHQlD'></center></pre></bdo></b><th id='yHQlD'></th></span></q></dt></tr></i><div id='yHQlD'><tfoot id='yHQlD'></tfoot><dl id='yHQlD'><fieldset id='yHQlD'></fieldset></dl></div>

        关于 cmdclass 参数的 pip3 和 `python3 setup.py install`

        时间:2023-09-13
        <i id='FMFw7'><tr id='FMFw7'><dt id='FMFw7'><q id='FMFw7'><span id='FMFw7'><b id='FMFw7'><form id='FMFw7'><ins id='FMFw7'></ins><ul id='FMFw7'></ul><sub id='FMFw7'></sub></form><legend id='FMFw7'></legend><bdo id='FMFw7'><pre id='FMFw7'><center id='FMFw7'></center></pre></bdo></b><th id='FMFw7'></th></span></q></dt></tr></i><div id='FMFw7'><tfoot id='FMFw7'></tfoot><dl id='FMFw7'><fieldset id='FMFw7'></fieldset></dl></div>

        <small id='FMFw7'></small><noframes id='FMFw7'>

          <bdo id='FMFw7'></bdo><ul id='FMFw7'></ul>

            1. <legend id='FMFw7'><style id='FMFw7'><dir id='FMFw7'><q id='FMFw7'></q></dir></style></legend>
                <tbody id='FMFw7'></tbody>
              <tfoot id='FMFw7'></tfoot>
                1. 本文介绍了关于 cmdclass 参数的 pip3 和 `python3 setup.py install` 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我尝试配置我的包,以便在安装过程中执行脚本.因此,我从 setuptools.command install 继承并创建了我的自定义类 ActionOnInstall 以在安装包时执行一些操作.此类通过 setuptools setup() 参数 cmdclass 调用,如 这里.

                  I tried to configure my package such that a script is executed on the installation process. Therefore, I inherited from setuptools.command install and created my custom class ActionOnInstall to do stuff when package is installed. This class is called via setuptools setup() argument cmdclass as described here.

                  这种 setup.py 文件的最小示例如下所示

                  A minimal example of such a setup.py file looks like

                  from setuptools import find_packages, setup
                  from setuptools.command.install import install
                  
                  
                  class ActionOnInstall(install):
                      def run(self):
                          print("Call install.run(self) works!")
                          install.run(self)
                  
                  
                  setup(name='name',
                        cmdclass={
                        'install': ActionOnInstall})
                  

                  通过执行构建包

                  pip3 install <path-to-dir-with-setup.py>
                  

                  运行成功,但不执行 ActionOnInstall.run() 中指定的命令.通过

                  runs successfully but does not execute commands specified in ActionOnInstall.run(). More directly calling this setup.py by

                  python3 setup.py install 
                  

                  执行 ActionOnInstall.run() 中指定的命令.

                  executes commands specified in ActionOnInstall.run().

                  然后,我发现自己在问:这两种安装包的方法的实际区别是什么.我知道,就像其他帖子告诉我们的那样,pip 让安装包的工作变得更轻松.但是没有解释这两种方法如何不同地处理 setup()cmdclass 参数.因此,我非常感谢你们的来信.

                  Then, I found myself asking: what is the actual difference of these both approaches to install a package. I know, like other posts tell us, pip makes life easier regarding package installation. But how these both approaches treat the cmdclass argument of setup() differently is not explained. Thus, I would highly appreciate to hear from you guys.

                  推荐答案

                  pip 调用你的 setup.py 但它重定向 stdout/stderr.测试 pip 下的 setup.py 写入固定位置的文件:

                  pip calls your setup.py but it redirects stdout/stderr. To test setup.py under pip write to a file in a fixed location:

                  class ActionOnInstall(install):
                      def run(self):
                          print("Call install.run(self) works!", file=open('/tmp/debug.log', 'w'))
                          install.run(self)
                  

                  pip install .

                  这篇关于关于 cmdclass 参数的 pip3 和 `python3 setup.py install` 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Pip 安装挂起 下一篇:从不同层次结构中导入 Python 模块

                  相关文章

                  最新文章

                  <tfoot id='GAVo8'></tfoot>

                  <small id='GAVo8'></small><noframes id='GAVo8'>

                      <i id='GAVo8'><tr id='GAVo8'><dt id='GAVo8'><q id='GAVo8'><span id='GAVo8'><b id='GAVo8'><form id='GAVo8'><ins id='GAVo8'></ins><ul id='GAVo8'></ul><sub id='GAVo8'></sub></form><legend id='GAVo8'></legend><bdo id='GAVo8'><pre id='GAVo8'><center id='GAVo8'></center></pre></bdo></b><th id='GAVo8'></th></span></q></dt></tr></i><div id='GAVo8'><tfoot id='GAVo8'></tfoot><dl id='GAVo8'><fieldset id='GAVo8'></fieldset></dl></div>

                      <legend id='GAVo8'><style id='GAVo8'><dir id='GAVo8'><q id='GAVo8'></q></dir></style></legend>

                      • <bdo id='GAVo8'></bdo><ul id='GAVo8'></ul>