【问题标题】:Dateutil package resulting in script crashingDateutil 包导致脚本崩溃
【发布时间】:2021-09-02 17:27:18
【问题描述】:

我正在运行一个使用以下包的 python 脚本

from dateutil.parser import parse

图书馆包括以下内容

    """This will take any date string and format into the date format you want    

    Args:
        date_str (string): Any date string 
        format (string): format you want 
        
    Example:    
        >>> my_date_format = format_date("2020-10-03", "%m/%d/%Y")
        >>> my_date_format = format_date("2020/10/03", "%m/%d/%Y")
        >>> my_date_format = format_date("10/03/2020", "%m-%d-%Y")
        >>> my_date_format = format_date("2018-06-29 08:15:27.243860", "%m-%d-%Y %H:%M:%S.%f")
        >>> my_date_format = format_date("10/06/2020 at 7:40AM", "%b %d %Y at %I:%M%p")        
    """
    dt = parse(date_str)
    return dt.strftime(format)

但是,当我运行任何利用上述内容的东西时,我会收到以下错误:

Traceback (most recent call last):
  File C:\Users\main\box\scripts\tests>python ra.py", line 26, in <module>
    from UtilLib import CodeStore, check_if_file_exists, getRandomUserInfo
  File "..\UtilLib.py", line 19, in <module>
    from dateutil.parser import parse
  File "C:\Python39\lib\site-packages\dateutil\parser.py", line 158
    l.append("%s=%s" % (attr, `value`))
                              ^
SyntaxError: invalid syntax```

The error seems to be associated with the dateutil package that was installed. I can't figure out how to fix this. Where do I start?

【问题讨论】:

    标签: python python-dateutil


    【解决方案1】:

    您似乎有一个用于 Python 2 的 dateutil 包版本,其中反引号用作 repr 的包装器,但您使用的是 Python 3。

    运行 pip install -U python-dateutil(或您用作包/依赖管理器的任何工具)以升级到支持您正在使用的 Python 版本的 dateutil 版本。

    【讨论】:

    • 我试过了,但是它返回了ERROR: Could not find a version that satisfies the requirement dateutil (from versions: none) ERROR: No matching distribution found for dateutil 然后我尝试完全卸载软件包,它说WARNING: Skipping dateutil as it is not installed. 但是当我回去重新安装它时,我得到Requirement already satisfied: python-dateutil in c:\python39\lib\site-packages (1.4)。有没有办法手动删除?
    • 这个包实际上在 PyPI 上叫做python-dateutil。我编辑了 DeepSpace 的答案以反映这一点。不过,不确定您从哪里得到坏包,这可能代表一个更深层次的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-29
    • 2020-07-26
    • 2016-08-28
    • 2018-01-23
    • 2020-12-02
    • 2013-11-11
    • 2011-01-24
    相关资源
    最近更新 更多