Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not import runpy module

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
like image 564
Gerald Murphy Avatar asked Jun 09 '17 17:06

Gerald Murphy


People also ask

Can't import Runpy module while building Python?

The runpy module is installed by default during the installation of the environment. So, there might be a problem with the installation of the virtual environment. This happens if the installation was cancelled in between or an old environment was not properly removed and it was overwritten.

What is Runpy?

The runpy module is used to locate and run Python modules without importing them first. Its main use is to implement the -m command line switch that allows scripts to be located using the Python module namespace rather than the filesystem.


2 Answers

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.

like image 51
user2760751 Avatar answered Sep 21 '22 11:09

user2760751


The runpy module is installed by default during the installation of the environment.

So, there might be a problem with the installation of the virtual environment. This happens if the installation was cancelled in between or an old environment was not properly removed and it was overwritten.

So, try to re-install the environment.

like image 40
Tushar Rajdev Avatar answered Sep 19 '22 11:09

Tushar Rajdev