Gekko Installation Problem

757 views
Skip to first unread message

Kai

unread,
Jul 31, 2018, 11:53:46 AM7/31/18
to apmonitor
Dear Dr. Hedengren,

thank you very much for your reply for the MPC problem. However, I got problems with gekko installation:  I installed gekko as the way you said in the lecture, but when I try to run the code: from gekko import GEKKO. I obtained the following error message: from gekko import GEKKO   ImportError: cannot import name 'GEKKO'. (You can also see from the picture below ). Then I checked the pip list, gekko is there. And the software I am using is Anaconda, Spyder. 

Do you know what is the root of this problem? Thank you! 

Looking forward to hearing from you!

Bests,

Kai




John Hedengren

unread,
Jul 31, 2018, 12:56:01 PM7/31/18
to APM Google Groups
Dear Kai,

This is often caused by multiple versions of Python with multiple pip versions. Could you try to install at the top of the script with:
try:
    from pip import main as pipmain
except:
    from pip._internal import main as pipmain
pipmain(['install','gekko'])
# to upgrade: pipmain(['install','--upgrade','gekko'])
This does a pip install that is for the distribution that you are running. You only need to run this once. 

Best regards,

John Hedengren


--
--
APMonitor user's group e-mail list.
- To post a message, send email to apmo...@googlegroups.com
- To unsubscribe, send email to apmonitor+...@googlegroups.com
- Visit this group at http://groups.google.com/group/apmonitor

---
You received this message because you are subscribed to the Google Groups "apmonitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apmonitor+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kai

unread,
Aug 1, 2018, 1:48:56 AM8/1/18
to apmonitor
Dear Dr. Hedengren,

thank you for your quick reply. I have done what you suggested, sadly,  I still got the same error message: ImportError: cannot import name 'GEKKO'. And I found in the path \anaconda3\lib\site-packages  exists a gekko package, but inside it, there is no program named GEKKO, as you can see from the picture. Do you know what could be other possible causes for the issue? Thank you!

With best wishes

Kai

Logan Beal

unread,
Aug 2, 2018, 2:53:34 PM8/2/18
to apmo...@googlegroups.com
Kai,

I've never seen this error before. GEKKO should be imported through the __init__.py script; it's a class defined in the gekko.py script. 

Can you send the output from this code, please?

import gekko
help(gekko)
dir(gekko)

Logan

On Tue, Jul 31, 2018 at 11:48 PM Kai <lippi...@gmail.com> wrote:
Dear Dr. Hedengren,

thank you for your quick reply. I have done what you suggested, sadly,  I still got the same error message: ImportError: cannot import name 'GEKKO'. And I found in the path \anaconda3\lib\site-packages  exists a gekko package, but inside it, there is no program named GEKKO, as you can see from the picture. Do you know what could be other possible causes for the issue? Thank you!

With best wishes

Kai








On Tuesday, July 31, 2018 at 11:53:46 PM UTC+8, Kai wrote:
Dear Dr. Hedengren,

thank you very much for your reply for the MPC problem. However, I got problems with gekko installation:  I installed gekko as the way you said in the lecture, but when I try to run the code: from gekko import GEKKO. I obtained the following error message: from gekko import GEKKO   ImportError: cannot import name 'GEKKO'. (You can also see from the picture below ). Then I checked the pip list, gekko is there. And the software I am using is Anaconda, Spyder. 

Do you know what is the root of this problem? Thank you! 

Looking forward to hearing from you!

Bests,

Kai




Kai

unread,
Aug 2, 2018, 7:08:44 PM8/2/18
to apmonitor
Dear Logan,

thank you for your help, below is the results of running the code:



And surprisingly, after running these three lines code, I run the whole process, it works successfully. But when I open a new console, try to run the same the process, when I run the code: import gekko, or run the whole process, I still obtain the error message: ImportError: cannot import name 'GEKKO', This is so weird, do you what I can do to fix this problem?

Thank you! In the attachment please find the code I am using.

Bests,

Kai 












On Tuesday, July 31, 2018 at 11:53:46 PM UTC+8, Kai wrote:
gekko.py

Logan Beal

unread,
Aug 2, 2018, 7:16:07 PM8/2/18
to apmo...@googlegroups.com
Kai,

Try renaming your file to anything besides gekko.py

When Python imports "gekko", it finds your gekko.py file before the gekko package. The error is because your script doesn't define "GEKKO". 

Logan

Kai

unread,
Aug 3, 2018, 9:27:21 AM8/3/18
to apmonitor
Hi Logan,

thank you so much, now the program runs perfectly!

Have a good day!

Bests,

Zeping




On Tuesday, July 31, 2018 at 11:53:46 PM UTC+8, Kai wrote:
Reply all
Reply to author
Forward
0 new messages