How do I install mitmproxy on ubuntu 18.0.4

I've been hammering away at this for about 2 days now and it doesn't matter what I try I cannot seem to make it work.

I've installed mitmproxy on the system as I need to diagnose an issue with an SSL connection, when I used apt-get to install it, it was happy it was satisfied with all the dependencies, yet every time I try to run it all I get is this:

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

I'm pretty sure that what I'm seeing is a hard coded dependency, IE: the author specifically wants that version and not the newer one that I do actually have installed.

I've tried until I'm blue in the face to install the many different variations on the version string I can find in the Ubuntu package search and various support places on the web, but nothing at all seems to work.

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

I'm running this under Ubuntu 18.0.4 LTS but just going round in circles, has anyone managed to get mitmproxy running on this OS?

Update 1

I've managed to get urwid 1.3.1 installed using pip but it's made no difference at all.

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

Update 2

Raffas answer below is the solution to fixing the problem (Or just DONT install mitmproxy using apt on ubnutu), one thing extra however, you might need to do a

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

After using Raffas answer as ubuntu seems to screw the path up and still keeps looking for the mitmproxy file in the old location.


I would recommend removing the mitmproxy package you installed using APT and installing it using PIP3 instead.


Firstly, run the following command in the terminal to remove apt installed mitmproxy package:

sudo apt remove mitmproxy

Secondly, install PIP3 if it is not installed by running the following command in the terminal:

sudo apt install python3-pip

Or update it if it is already installed by running the following command in the terminal:

sudo pip3 install -U pip

Thirdly, install mitmproxy via PIP3 by running the following command in the terminal:

sudo pip3 install mitmproxy

Finally, type mitmproxy in the terminal and press Enter to start it.