Error trying to start ardupilot

I am getting an error when trying to start my ardupilot build.
When I run: -w

I get the error:

Traceback (most recent call last):
  File "/home/mikeyjoyce/ardupilot/Tools/autotest/", line 31, in <module>
    from pysim import util
  File "/home/mikeyjoyce/ardupilot/Tools/autotest/pysim/", line 16, in <module>
    import pexpect
ImportError: No module named pexpect

Which is strange since pexpect is installed on my system which is proved by the following command and output:

pip3 show pexpect

And the output:

Name: pexpect
Version: 4.8.0
Summary: Pexpect allows easy control of interactive console applications.
Author: Noah Spurrier; Thomas Kluyver; Jeff Quast
License: ISC license
Location: /home/mikeyjoyce/.local/lib/python3.6/site-packages
Requires: ptyprocess

Try this instead:

pip show pexpect

Your system may have 2 python installs (python/pip and python3/pip3) - so best to check both.

When I run

pip show pexpect

I get the following output:

Command 'pip' not found, but can be installed with:

sudo apt install python-pip

Also I forgot to mention the operating system that I am running is Ubuntu 18.04

Seems maybe you have the package installed locally for a virtual environment rather than globally.

How do I install globally?

I was able to get past it with the following command:

sudo apt install python-matplotlib python-serial python-wxgtk3.0 python-wxtools python-lxml python-scipy python-opencv ccache gawk python-pip python-pexpect

But now I have a problem still with -w

The output says:

Traceback (most recent call last):
  File "/home/mikeyjoyce/ardupilot/Tools/autotest/", line 31, in <module>
    from pysim import util
  File "/home/mikeyjoyce/ardupilot/Tools/autotest/pysim/", line 18, in <module>
    from pymavlink.rotmat import Vector3, Matrix3
ImportError: No module named pymavlink.rotmat

I have installed pymavlink with pip

You can try using this script.

Yeah, I did that script. I eventually got it working I think @stephendade was correct in my system having python 2 also on the system. I just installed the prereqs for each python version