ImportError: No module named 'thread'

前端 未结 5 448
Happy的楠姐
Happy的楠姐 2021-01-02 01:28

when I run mitmproxy command in command line, I get the following error.

% mitmproxy
Traceback (most recent call last):
  File \"/usr/local/bin/mitmproxy\",          


        
相关标签:
5条回答
  • 2021-01-02 01:46

    You are trying to run Python 2 code on Python 3, which will not work.

    As of April 2016, mitmproxy only supports Python 2.7. We're actively working to fix that in the next months, but for now you need to use Python 2 or the binaries provided at http://mitmproxy.org.

    As of August 2016, the development version of mitmproxy now supports Python 3.5+. The next release (0.18) will be the first one including support for Python 3.5+.

    As of January 2017, mitmproxy only supports Python 3.5+.

    0 讨论(0)
  • 2021-01-02 01:49

    The name of the file saved could be threading, this would give an error as threading is a predefined class in Python. Try changing the name of your file. It would help....

    0 讨论(0)
  • 2021-01-02 01:56

    Go to you site-packages folder, create a file called thread.py and paste this code in it:

    from _thread import *
    __all__ = ("error", "LockType", "start_new_thread", "interrupt_main", "exit", "allocate_lock", "get_ident", "stack_size", "acquire", "release", "locked")
    

    This creates an 'alias' for the module _thread called thread. While the _thread module is very small, you can use dir() for bigger modules:

    # Examle for the Cookies module which was renamed to http.cookies:
    # Cookies.py in site-packages
    import http.cookies
    __all__ = tuple(dir(http.cookies))
    

    Hope this helps!

    0 讨论(0)
  • 2021-01-02 02:06

    In Python 3 instead of:

    import thread
    

    Do:

    import _thread
    
    0 讨论(0)
  • 2021-01-02 02:09

    Easiest solution is to create a virtualenv with python2 and run mitmproxy on this virtualenv

    virtualenv -p `which python2` .env
    source .env/bin/activate
    pip install mitmproxy
    .env/bin/mitmproxy
    
    0 讨论(0)
提交回复
热议问题