【问题标题】:How to handle 'ImportError: No module named profanity_check'如何处理“ImportError:没有名为 profanity_check 的模块”
【发布时间】:2019-05-07 20:57:25
【问题描述】:

我正在尝试让 profanity_check 在 EC2 Linux 实例上运行。

问题是当我尝试使用 python34 profanity.py 运行 profanity.py 时收到 ImportError: No module named profanity_check 错误。

此外,当尝试运行 python profanity.py 时,我收到 ValueError: unsupported pickle protocol: 3 错误。

我认为这是因为 profanity_check 仅适用于 Python 3。

此外,我在安装 profanity-check 时收到了 DEPRECATION: Python 2.7 will reach the end of its life 警告。但是,我已经在系统上安装了 Python 3.4.9。

根据这个问题here 我已经检查了__init__.py 文件。它存在并且看起来很稳定。

__init__.py 文件的路径如下:

/home/ec2-user/.local/lib/python2.7/site-packages/profanity_check/init.py

这可能是什么问题?

profanity.py

#!/usr/bin/python34

from profanity_check import predict, predict_prob

predict(['predict() takes an array and returns a 1 for each string if it is offensive, else 0.'])
# [0]

__init__.py

from .profanity_check import predict, predict_prob
__version__="1.0.2"

【问题讨论】:

    标签: python linux amazon-ec2 package


    【解决方案1】:

    您已经为 Python 2.7 安装了 profanity_check

    /home/ec2-user/.local/lib/python2.7/site-packages/profanity_check/__init__.py
    

    但是您的脚本是使用 Python 3.4 运行的

    #!/usr/bin/python34 <-- this here
    
    from profanity_check import predict, predict_prob
    

    更改您的脚本以使用 python2.7 或为 python3.7 安装 profanity_check

    【讨论】:

    • 非常感谢rdas!似乎 profanity_check 仅适用于 Python 3。这就是为什么我在尝试使用 Python 2 编译时收到“ValueError: unsupported pickle protocol:3”错误。更新 Python 3 并安装 pip 3 后,我设法让它工作。
    猜你喜欢
    • 1970-01-01
    • 2020-01-23
    • 2014-10-22
    • 2013-03-11
    • 2013-06-04
    • 1970-01-01
    • 2012-12-07
    • 2015-01-17
    相关资源
    最近更新 更多