No module named 'searchtweets'



Im not too familiar with python and searchtweets package. I installed searchtweets package but Im getting following error.

!pip install searchtweets

Collecting searchtweets
Collecting tweet-parser (from searchtweets)
Collecting pyyaml (from searchtweets)
Collecting requests (from searchtweets)
  Using cached
Collecting idna<2.8,>=2.5 (from requests->searchtweets)
  Using cached
Collecting urllib3<1.25,>=1.21.1 (from requests->searchtweets)
  Using cached
Collecting certifi>=2017.4.17 (from requests->searchtweets)
  Using cached
Collecting chardet<3.1.0,>=3.0.2 (from requests->searchtweets)
  Using cached
Installing collected packages: tweet-parser, pyyaml, idna, urllib3, certifi, chardet, requests, searchtweets
Successfully installed certifi-2018.10.15 chardet-3.0.4 idna-2.7 pyyaml-3.13 requests-2.20.0 searchtweets-1.2.1 tweet-parser-1.13.1 urllib3-1.24

from searchtweets import ResultStream, gen_rule_payload, load_credentials
premium_search_args = load_credentials("~/.twitter_keys.yaml",

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-7-1a8baa28f761> in <module>
----> 1 from searchtweets import ResultStream, gen_rule_payload, load_credentials
      4 premium_search_args = load_credentials("~/.twitter_keys.yaml",
      5                                        yaml_key="search_tweets_premium",

ModuleNotFoundError: No module named 'searchtweets'

Is there anyone familiar with this problem

Thank you.


Thanks for reaching out here. I was just using the searchtweets Python wrapper this week.

A few things might be going on here:

  1. Usually when I run into issues like this it’s because I’m using a machine where I have Python 2 and 3 installed. You might want to try using this pip3 install searchtweets if you are usng Python 3.

  2. If this doesn’t work you might want to consider using pipenv for this.

  3. You may also want to try installing without the ! so just pip install searchtweets

Thanks for reaching out! Hope this helps, please let us know if you need anything else here.


Thank you. pip3 install searchtweets worked for me.

But then I got this error.

cannot read file .twitter_keys.yaml
Error parsing YAML file; searching for valid environment variables
Account type is not specified and cannot be inferred.
        Please check your credential file, arguments, or environment variables
        for issues. The account type must be 'premium' or 'enterprise'.

KeyError                                  Traceback (most recent call last)
<ipython-input-10-8ba2288056a6> in <module>
      4 premium_search_args = load_credentials(".twitter_keys.yaml",
      5                                        yaml_key="search_tweets_premium",
----> 6                                        env_overwrite=False)

~/.local/lib/python3.6/site-packages/searchtweets/ in load_credentials(filename, account_type, yaml_key, env_overwrite)
    187                    if env_overwrite
    188                    else merge_dicts(env_vars, yaml_vars))
--> 189     parsed_vars = _parse_credentials(merged_vars, account_type=account_type)
    190     return parsed_vars

~/.local/lib/python3.6/site-packages/searchtweets/ in _parse_credentials(search_creds, account_type)
     80         """
     81         logger.error(msg)
---> 82         raise KeyError
     84     try:


I have ~/.twitter_keys.yaml file in same directory with my code file.

twitter_keys.yaml contains this

  account_type: premium
  # if you have a bearer token, you can use it below. otherwise, swap the comment marks and use 
  # your app's consumer key/secret - the library will generate and use a bearer token for you. 
  # bearer_token: <A_VERY_LONG_MAGIC_STRING>	
  consumer_key: xxxxxxx
  consumer_secret: xxxxxxxxxxx


By default, this library expects this file at "~/.twitter_keys.yaml"

Try saving the yaml file in your home directory.


If the file is in same directory you can use this syntax:

premium_search_args = load_credentials(filename="twitter_keys.yaml", 


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.