首页 > 解决方案 > 错误 AttributeError:模块 'twint' 没有属性 'config'

问题描述

我已经安装twint了:

git clone --depth=1 https://github.com/twintproject/twint.git
cd twint
pip3 install . -r requirements.txt

这导致安装成功:

Successfully installed twint-2.1.21

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

AttributeError                            Traceback (most recent call last)
<ipython-input-6-f48dbefa5025> in <module>
      1 # Configure
----> 2 c = twint.Config()
      3 c.Search = "wfh"
      4 
      5 # Run

AttributeError: module 'twint' has no attribute 'Config'

这是我的代码:

import twint
# Configure
c = twint.Config()
c.Search = "wfh"

# Run
twint.run.Search(c)

标签: cmdjupyter-notebookconfig

解决方案


只需将脚本 twint 安装在“/home/yourusername/.local/bin”中的位置添加到路径。

export PATH="/home/yourusername/.local/bin:$PATH"

您需要获取 .bashrc 或注销/登录(或重新启动终端)才能使更改生效。要获取 .bashrc,只需键入

source ~/.bashrc

然后重新启动你的 jupyter 笔记本。这应该解决它


推荐阅读