【问题标题】:How to fix: AttributeError: module 'twint' has no attribute 'config'如何修复:AttributeError:模块'twint'没有属性'config'
【发布时间】:2020-01-07 14:53:07
【问题描述】:

我已经安装了 twint:

pip3 install twint

这导致安装成功:

Successfully installed twint-2.1.8

它可以使用命令提示符(CLI)命令从twitter 获取推文,但是当我尝试在Spyder IDE 中运行示例时,它给了我错误:

"Traceback (most recent call last):
     File "<ipython-input-13-7b77905cef0c>", line 1, in <module>
        runfile('C:/Users/myname/twint.py', wdir='C:/Users/myname')
      File "C:\Users\myname\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
       execfile(filename, namespace)
      File "C:\Users\myname\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
        exec(compile(f.read(), filename, 'exec'), namespace)
      File "C:/Users/myname/twint.py", line 8, in <module>
        import twint
      File "C:\Users\myname\twint.py", line 9, in <module>
        c = twint.Config()
    AttributeError: module 'twint' has no attribute 'Config'

这是我的代码:

import twint
c = twint.Config()
c.Username = "twitterAccountName"
twint.run.Search(c)

但是,我在 GitHub 上查看了与 twint 相关的问题,发现 here 但此处提供的解决方案对我不起作用。有谁知道错误来自哪里?我该如何解决?

【问题讨论】:

    标签: python-3.x config python-module attributeerror


    【解决方案1】:

    您链接到的问题与您遇到的问题完全相同。您需要将文件重命名为不是 twint.py

    重命名此文件runfile('C:/Users/myname/twint.py

    如果您遇到其他错误,那么这是一个单独的问题

    【讨论】:

    • @cricket_007 我把文件名改成了scrape.py,但是没有解决。它给了我同样的AttributeError
    • @OneCricketeer 这解决了我的问题,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 2019-08-25
    • 2020-09-03
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多