python - 导入错误 : No module named 'thread'

标签 python mitmproxy

当我运行 mitmproxy命令行中的命令,我收到以下错误。

% mitmproxy
Traceback (most recent call last):
  File "/usr/local/bin/mitmproxy", line 7, in <module>
    from libmproxy.main import mitmproxy
  File "/usr/local/lib/python3.5/site-packages/libmproxy/main.py", line 5, in <module>
    import thread
ImportError: No module named 'thread'

我用谷歌搜索了这个错误并找到了这个 stackoverflow Q&A 页面。

pydev importerror: no module named thread, debugging no longer works after pydev upgrade

根据上面的页面,发生错误是因为模块“thread”在python3中被重命名为“_thread”。

所以,我知道是什么导致了这个错误,但是然后呢?

我不知道现在该怎么做才能摆脱这个错误。

我是 python 新手。我刚刚安装了 Python 和 pip如下图所示进入我的 mac OSX,因为我想使用 mitmproxy .
% which pip
/usr/local/bin/pip
% pip --version
pip 8.1.1 from /usr/local/lib/python3.5/site-packages (python 3.5)

% which python
/usr/bin/python
% which python3
/usr/local/bin/python3

% python --version
Python 2.7.10
% python3 --version
Python 3.5.1

谁能告诉我现在该怎么办?

附加信息

正如@linusg 回答的那样,我在“site-packages”目录中创建了“thread.py”文件,并将下面的代码粘贴到“thread.py”中
from _thread import *
__all__ = ("error", "LockType", "start_new_thread", "interrupt_main", "exit", "allocate_lock", "get_ident", "stack_size", "acquire", "release", "locked")

在我这样做之后,“ImportError: No module named 'thread'”消失了,但现在我有另一个 ImportError,即“import Cookie ImportError: No module named 'Cookie'”。

似乎在 Python 3 中,Cookie模块重命名为 http.cookies (stackoverflow.com/questions/3522029/django-mod-python-error)。

现在我该怎么办?

我在“站点包”目录 中的内容
% ls /usr/local/lib/python3.5/site-packages                                                  (git)-[master]
ConfigArgParse-0.10.0.dist-info/                mitmproxy-0.15.dist-info/
OpenSSL/                                        netlib/
PIL/                                            netlib-0.15.1.dist-info/
Pillow-3.0.0.dist-info/                         passlib/
PyYAML-3.11.dist-info/                          passlib-1.6.5.dist-info/
__pycache__/                                    pathtools/
_cffi_backend.cpython-35m-darwin.so*            pathtools-0.1.2.dist-info/
_markerlib/                                     pip/
_watchdog_fsevents.cpython-35m-darwin.so*       pip-8.1.1.dist-info/
argh/                                           pkg_resources/
argh-0.26.1.dist-info/                          pyOpenSSL-0.15.1.dist-info/
backports/                                      pyasn1/
backports.ssl_match_hostname-3.5.0.1.dist-info/ pyasn1-0.1.9.dist-info/
blinker/                                        pycparser/
blinker-1.4.dist-info/                          pycparser-2.14.dist-info/
certifi/                                        pyparsing-2.0.7.dist-info/
certifi-2016.2.28.dist-info/                    pyparsing.py
cffi/                                           pyperclip/
cffi-1.6.0.dist-info/                           pyperclip-1.5.27.dist-info/
click/                                          setuptools/
click-6.2.dist-info/                            setuptools-19.4-py3.5.egg-info/
configargparse.py                               sitecustomize.py
construct/                                      six-1.10.0.dist-info/
construct-2.5.2.dist-info/                      six.py
cryptography/                                   test/
cryptography-1.1.2.dist-info/                   thread.py
easy_install.py                                 tornado/
hpack/                                          tornado-4.3.dist-info/
hpack-2.0.1.dist-info/                          urwid/
html2text/                                      urwid-1.3.1.dist-info/
html2text-2015.11.4.dist-info/                  watchdog/
idna/                                           watchdog-0.8.3.dist-info/
idna-2.1.dist-info/                             wheel/
libmproxy/                                      wheel-0.26.0-py3.5.egg-info/
lxml/                                           yaml/
lxml-3.4.4.dist-info/

最佳答案

在 Python 3 中,而不是:

import thread
做:
import _thread

关于python - 导入错误 : No module named 'thread' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39876943/

相关文章:

python - python folium(map.html文件)与dash应用程序集成后如何刷新?

python - 我该如何修复这个 mitmproxys SyntaxError?

proxy - mitmproxy 安装错误

windows - 无法以编程方式将 mitmproxy .p12 证书添加到 Windows

python - Mitmproxy 上游服务器

Python 单元测试 : AttributeError: no attribute 'assertTrue' when running on Linux

python - 文件未找到错误: using Pandas

proxy - 无法使用 mitmproxy 查看 WhatsApp 流量

python - 与 Tensorflow 中的常规 LSTMCell 相比,使用 CudnnLSTM 训练时的不同结果

python - Python中dict的元组列表