Forums

ImportError: No module named 'thread'

I am trying to host my web application on pythonanywhere. It is a simple web application that streams data from twitter through tweepy and then prints it on a website via flask. However, when I try to run the flask file for my tweepy data to be streamed to my site I receive an error that reads:

ImportError: No module named 'thread'

I have tried installing the thread package through the bash console:

 ~ $ pip install --user thread
Collecting thread Could not find a version that satisfies the requirement thread (from versions: )No matching distribution found for thread20:21 ~ $

I need to use the thread package because i need to run my tweepy file and flask file as seperate threads if not they conflict with eachother.

I have also tried the "_thread" alternative but I receive a different console error when I try to install that package:

~ $ pip install --user _thread
Invalid requirement: '_thread'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 78, in __init__
    req = Requirement(req)
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/packaging/requirements.py", line 96, in __init__
    requirement_string[e.loc:e.loc + 8]))
InvalidRequirement: Invalid requirement, parse error at "'_thread'"

I also manually changed my code to use "_thread" instead of "thread" but when I did that my website would not run at all. Here is my error log.

ImportError: No module named _thread
2016-08-05 06:39:58,772 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:42:02,446 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:42:05,176 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:42:14,318 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:42:15,237 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:43:12,237 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:44:12,009 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:44:36,169 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:44:40,067 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:45:58,200 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:46:08,075 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:46:10,934 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:46:40,814 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:47:15,736 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:47:17,266 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:49:22,347 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:50:07,803 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:50:12,453 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:54:13,019 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread
2016-08-05 06:54:18,306 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
ImportError: No module named _thread

P.S. I am using Python 2.7

The Python threading module is built in, and is imported by using import threading rather than import thread.

But there's an extra thing here -- we don't support threads in web apps. If you want to build a web app that has a second component that runs separately, we recommend you use a scheduled task to keep the second component running in a separate process.