Search code examples
pythongekko

How do I solve the - ModuleNotFoundError: No module named 'gekko', in spyder?


I have installed the gekko package and have updated pip to its latest version. I have run the 'pip list' command and confirmed that the gekko package is installed. In fact, I can use the gekko package with the sublime editor on the same machine with the same script but the same script throws the ModuleNotFoundError: No module named 'gekko' error when I try to run it in a spyder editor. I have python versions 3.6 and 3.9 installed and running on windows 10.


Solution

  • In addition to the great suggestion by @Ghoti to change to another Python version in Spyder, it is also easy to install gekko on another version such as the distribution that comes with an Anaconda install. An easy way to find Python distributions is to run which python or which python3 from the command line.

    john@aps:~/Desktop$ which python3
    /usr/bin/python3
    

    When you find the correct path to the distribution, try the following with the correct absolute path:

    /usr/bin/python3 -m pip install gekko
    

    Many don't use the system python in /usr/bin/ but will create a virtual environment with venv or similar method to maintain separate python installations. If you have an Anaconda distribution then you can start an Anaconda prompt and try pip or pip3 to install gekko.

    pip install gekko
    

    The following isn't the recommended method (actively discouraged) to use pip in a script:

    try:
        from pip import main as pipmain
    except:
        from pip._internal import main as pipmain
    pipmain(['install','gekko'])
    # to upgrade: pipmain(['install','--upgrade','gekko'])