Could not import runpy module

Gerald Murphy picture Gerald Murphy · Jun 9, 2017 · Viewed 30.3k times · Source

I am trying to install a Python module on a raspberry pi that is running linux. I am using Python 2.7.11 and have tried the following commands:

python -m pip install schedule

python -m easy_install schedule

python2.7 -m pip install schedule

In each case I get the same error message:

Could not import runpy module

I get this same error message no matter what module I try to install. What could be causing this problem? I have been unable to find anything useful from Google searches I've done on the error message.

EDIT:

When I try adding sudo to the command like either of these:

sudo python -m pip install schedule or sudo /usr/bin/python -m pip install schedule

I get the error:

-sh: sudo: not found

EDIT2:

When I try python -m pip install runpy I still get:

Could not import runpy module

Answer

user2760751 picture user2760751 · Oct 9, 2017

I've encountered the same error, hoping my own experience will do some help. First check your PYTHONPATH (by executing 'echo $PYTHONPATH' in your shell) to see if it is empty. Normally it should be empty. But if it isn't, you have to explicitly put your python corresponding library path to it.

In my own environment, the wrong configuration is:

export PYTHONPATH=/mnt/usb/srv/homeassistant/lib/python3.4/site-packages

and my python location is:

/usr/bin/python

So, I append my python's library path to the configuration(don't forget the ':'):

export PYTHONPATH=/mnt/usb/srv/homeassistant/lib/python3.4/site-packages:/usr/lib/python3.6/site-packages:/usr/lib/python3.6/site-packages

The error is gone now.