简体   繁体   English

exceptions.ImportError:无法导入名称 TwitterAPI

[英]exceptions.ImportError: cannot import name TwitterAPI

Keep getting this error and not sure why,不断收到这个错误,不知道为什么,

exceptions.ImportError: cannot import name TwitterAPI

TwitterAPI library is already downloaded, I download it first from pip install twitterapi, didnt work, uninstall it and download the .zip file for it, and tried to install it using TwitterAPI 库已经下载,我首先从 pip install twitterapi 下载它,没有用,卸载它并下载它的 .zip 文件,并尝试使用安装它

python setup.py build
python setup.py install

didnt work too, still getting the same error, any ideas?也没有工作,仍然出现同样的错误,有什么想法吗?

the code:编码:

from TwitterAPI import TwitterAPI

TRACK_TERM = 'NBA'

api = TwitterAPI(consumer_key='__', consumer_secret='__', access_token_key='__', access_token_secret='__')

r = api.request('statuses/filter', {'track': TRACK_TERM})

for item in r:
    print (item['text'] if 'text' in item else item)

You should to install requests (or upgrade them) like in this issue .您应该像本期一样安装请求(或升级它们)。

pip install requests

or或者

pip install --upgrade requests

请编写此设置的命令:

pip install python-twitter

Because you installed TwitterAPI from a zip file, the package is not necessarily in a path where Python will see it.因为您从 zip 文件安装 TwitterAPI,所以该包不一定位于 Python 可以看到它的路径中。 That is why import fails.这就是导入失败的原因。 Your best bet is to try installing with pip again, but this time use the proper case since pip is case sensitive:最好的办法是再次尝试使用 pip 安装,但这次使用正确的大小写,因为 pip 区分大小写:

pip install TwitterAPI

可能需要设置 PYTHONPATH:

export PYTHONPATH=`pwd`

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM