ModuleNotFoundError: No module named 'pygam'

2.2k Views Asked by At

I'm trying to execute a python script which pygam ( from pygam import LogisticGAM, LinearGAM ).

when I'm trying to execute this script  I have this error: ModuleNotFoundError: No module named 'pygam'

The problem that pygam is installed with both pip and pip3.

This the result when I try to re-install it using pip:

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
WARNING: The directory '/home/mobelite/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/home/mobelite/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: pygam in /usr/local/lib/python2.7/dist-packages (0.8.0)
Requirement already satisfied: scipy in /usr/local/lib/python2.7/dist-packages (from pygam) (1.2.2)
Requirement already satisfied: future in /usr/local/lib/python2.7/dist-packages (from pygam) (0.17.1)
Requirement already satisfied: numpy in /usr/local/lib/python2.7/dist-packages (from pygam) (1.16.5)
Requirement already satisfied: progressbar2 in /usr/local/lib/python2.7/dist-packages (from pygam) (3.47.0)
Requirement already satisfied: six in /usr/local/lib/python2.7/dist-packages (from progressbar2->pygam) (1.12.0)
Requirement already satisfied: python-utils>=2.3.0 in /usr/local/lib/python2.7/dist-packages (from progressbar2->pygam) (2.3.0)

and this is the result when I try to re-install them using pip3:

The directory '/home/mobelite/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/mobelite/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied (use --upgrade to upgrade): pygam in /usr/local/lib/python3.5/dist-packages
Requirement already satisfied (use --upgrade to upgrade): future in /usr/local/lib/python3.5/dist-packages (from pygam)
Requirement already satisfied (use --upgrade to upgrade): progressbar2 in /usr/local/lib/python3.5/dist-packages (from pygam)
Requirement already satisfied (use --upgrade to upgrade): numpy in ./.local/lib/python3.5/site-packages (from pygam)
Requirement already satisfied (use --upgrade to upgrade): scipy in ./.local/lib/python3.5/site-packages (from pygam)
Requirement already satisfied (use --upgrade to upgrade): python-utils>=2.3.0 in /usr/local/lib/python3.5/dist-packages (from progressbar2->pygam)
Requirement already satisfied (use --upgrade to upgrade): six in ./.local/lib/python3.5/site-packages (from progressbar2->pygam)
You are using pip version 8.1.1, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

I found this is normal because I just install it, but I don't understand why they don't see pygam

2

There are 2 best solutions below

0
Carlos Cercado On BEST ANSWER

Make sure you are not using virtual environment, you must install pygame, just run the following command:

pip install pygame

Install it and try again. More information visit https://pypi.org/project/pygame/

6
Amit Yadav On

Make sure you have the right versions of python and pip. Try installing it again with python (with the correct version) you are using to run the script. For example, you want to run it with [yhon3.5 use the below command:

python3.5 -m pip install pygam

I am assuming python3.5 in the above command invokes Python 3.5, on my system I have python3 invoke Python 3.5

Give the install a try with sudo as well

sudo pip install pygam
# OR
sudo pip3 install pygam

pip -V command will you the currently running version of pip and the python version it is installed in. Example:

pip -V
 pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

pip3 -V
 pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

The above comes handy if multiple versions of python are installed on a system. Let us know if it helps.