如何在 ubuntu 18.0.4 上安装 mitmproxy

如何在 ubuntu 18.0.4 上安装 mitmproxy

我已经为此努力了大约两天,但无论我怎么尝试,似乎都无法让它发挥作用。

我在系统上安装了 mitmproxy,因为我需要诊断 SSL 连接的问题,当我使用 apt-get 安装它时,很高兴它满足所有依赖项,但每次我尝试运行它时,我得到的都是:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 574, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 892, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 783, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (urwid 2.0.1 (/usr/lib/python3/dist-packages), Requirement.parse('urwid<1.4,>=1.3.1'), {'mitmproxy'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/mitmproxy", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3088, in <module>
    @_call_aside
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3072, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3101, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 576, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 589, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 778, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'urwid<1.4,>=1.3.1' distribution was not found and is required by mitmproxy

我很确定我看到的是一个硬编码依赖项,即:作者特别想要那个版本,而不是我实际安装的较新版本。

我曾尝试安装可以在 Ubuntu 软件包搜索和网络上的各种支持位置找到的版本字符串的许多不同变体,直到我筋疲力尽,但似乎没有任何效果。

sudo apt install python-urwid=1.3.1-2build1
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Version ‘1.3.1-2build1’ for ‘python-urwid’ was not found
shawty@sparkdev:~$ sudo apt install python-urwid=1.3.1-1
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Version ‘1.3.1-1’ for ‘python-urwid’ was not found
shawty@sparkdev:~$ sudo apt install python-urwid=1.3.1
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Version ‘1.3.1’ for ‘python-urwid’ was not found

我在 Ubuntu 18.0.4 LTS 下运行它,但只是兜圈子,有人设法让 mitmproxy 在这个操作系统上运行吗?

更新 1

我已经设法使用 pip 安装了 urwid 1.3.1,但没有任何区别。

Collecting urwid==1.3.1
  Downloading https://files.pythonhosted.org/packages/85/5d/9317d75b7488c335b86bd9559ca03a2a023ed3413d0e8bfe18bea76f24be/urwid-1.3.1.tar.gz (588kB)
    100% |████████████████████████████████| 593kB 921kB/s
Building wheels for collected packages: urwid
  Running setup.py bdist_wheel for urwid ... done
  Stored in directory: /root/.cache/pip/wheels/4d/3b/b8/723815509f0e45f878e8b244ac714033c72703b6b27324eee0
Successfully built urwid
Installing collected packages: urwid
  Found existing installation: urwid 2.0.1
    Not uninstalling urwid at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed urwid-1.3.1
root@sparkdev:/home/xavier/.ssh# mitmproxy
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 574, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 892, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 783, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (urwid 2.0.1 (/usr/lib/python3/dist-packages), Requirement.parse('urwid<1.4,>=1.3.1'), {'mitmproxy'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/mitmproxy", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3088, in <module>
    @_call_aside
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3072, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3101, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 576, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 589, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 778, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'urwid<1.4,>=1.3.1' distribution was not found and is required by mitmproxy

更新 2

以下是 Raffas 的回答,可以解决这个问题(或者不要在 ubnutu 上使用 apt 安装 mitmproxy),不过还有一件事,你可能需要做一个

ln -s /usr/local/bin/mitmproxy /usr/bin/mitmproxy

在使用 Raffas 答案之后,ubuntu 似乎搞乱了路径并且仍然在旧位置寻找 mitmproxy 文件。

答案1

我建议删除mitmproxy使用 APT 安装的软件包,然后使用 PIP3 安装它。


首先,在终端中运行以下命令来删除 apt 安装的mitmproxy包:

sudo apt remove mitmproxy

第二,如果尚未安装 PIP3,请通过在终端中运行以下命令来安装:

sudo apt install python3-pip

或者,如果已经安装,则通过在终端中运行以下命令来更新它:

sudo pip3 install -U pip

第三,mitmproxy通过在终端中运行以下命令通过 PIP3安装:

sudo pip3 install mitmproxy

最后,mitmproxy在终端中输入并按Enter启动它。

相关内容