简体   繁体   English

使用setuptools(pip)时如何打印警告和错误

[英]How to print warnings and errors when using setuptools (pip)

I am using setuptools to package code such that it can be easily installed using 我正在使用setuptools打包代码,以便可以使用以下命令轻松安装

cd project_name && pip install .

During the setup process, I want to warn the user about pre-existing config files and print some post install instructions on the system. 在设置过程中,我想警告用户有关预先存在的配置文件,并在系统上打印一些安装后的说明。 For example 例如

/etc/project_name/project.conf exists. Not copying default config file.

I have tried to use print and logging.warning() but still the warnings don't appear when installing using pip. 我尝试使用printlogging.warning()但使用pip安装时仍然没有出现警告。 I have a feeling I am missing something obvious. 我感觉自己缺少明显的东西。

We are trying to support 3.0 > python >= 2.6 on Redhat family >= el6 and Ubuntu >= 14.04LTS 我们正在尝试在Redhat系列> = el6和Ubuntu> = 14.04LTS上支持3.0> python> = 2.6

If you take a look at the pip source, in the function responsible for running the setup script, call_subprocess ( source here ), it says: 如果您看一下pip源代码,那么在负责运行安装脚本的函数call_subprocess此处的源代码 )中,它说:

def call_subprocess(cmd, show_stdout=True, cwd=None, ...
    ...
    # The obvious thing that affects output is the show_stdout=
    # kwarg. show_stdout=True means, let the subprocess write directly to our
    # stdout. Even though it is nominally the default, it is almost never used
    # inside pip (and should not be used in new code without a very good
    # reason); as of 2016-02-22 it is only used in a few places inside the VCS
    # wrapper code. Ideally we should get rid of it entirely, because it
    # creates a lot of complexity here for a rarely used feature.
    #
    # Most places in pip set show_stdout=False. What this means is:
    # - We connect the child stdout to a pipe, which we read.
    # - By default, we hide the output but show a spinner -- unless the
    #   subprocess exits with an error, in which case we show the output.
    # - If the --verbose option was passed (= loglevel is DEBUG), then we show
    #   the output unconditionally. (But in this case we don't want to show
    #   the output a second time if it turns out that there was an error.)

In short, you can see the output only if: 简而言之,只有在以下情况下,您才能看到输出:

  • your setup exits with an error, or 您的设置退出并出现错误,或者
  • user calls pip with -v , the verbose flag 用户使用-v (详细标志)调用pip

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 setuptools 构建 sphinx 文档时如何将警告转化为错误? - How to turn warnings into errors when building sphinx documentation with setuptools? 在OSX上使用pip安装Scrapy时出现错误和警告 - Errors and Warnings when installing Scrapy with pip on OSX 使用自签名证书将pip安装到私有pypi服务器时如何忽略抛出的安全警告 - How to ignore security warnings thrown when using pip install to private pypi server using self signed cert 使用setuptools构建鸡蛋时,如何以编程方式检测错误? - How can I detect errors programatically when building an egg with setuptools? 在使用setuptools构建软件包时,如何避免无效警告? - How can I avoid getting useless warnings while building my package using setuptools? 使用pip安装pandas时出错 - Getting errors when using pip to install pandas 使用Popen.communicate时如何将警告与stderr中发现的错误分开? - How to separate warnings from errors found in stderr when using Popen.communicate? 如何在开发 package(我正在使用 Spyder)时禁用由于星形导入导致的警告和错误? - How to disable warnings and errors due to star import when developing a package (I am using Spyder)? 如何在使用Python 2解释器时删除Pycharm中的print语句的Python 3警告? - How to remove Python 3 warnings for print statements in Pycharm when using the Python 2 interpreter? 使用键入和分配错误值时不显示警告/通知/错误 - No warnings/notification/errors displayed when using typing and assigning wrong values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM