Python editors and pyomo

2,781 views
Skip to first unread message

lbertolotti

unread,
May 2, 2015, 12:53:32 AM5/2/15
to pyomo...@googlegroups.com
I was trying to run pyomo on Spyder:

 from pyomo.environ import *

Works on Ubuntu terminal, but Spyder tells me:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pyomo.environ

Anyone knows why?

Cristián Serpell

unread,
May 2, 2015, 9:18:05 AM5/2/15
to pyomo...@googlegroups.com
I don't know Spyder, but probably there is a setting where you can set where your python libraries/interpreter are installed. Otherwise you can set your PYTHONPATH environment variable to the right directory where pyomo is installed.

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

lbertolotti

unread,
May 2, 2015, 2:33:26 PM5/2/15
to pyomo...@googlegroups.com, cris...@serpell.cl
Can you tell what's wrong?


Spyder_pythonpath.png

Watson, Jean-Paul

unread,
May 3, 2015, 9:51:10 PM5/3/15
to pyomo...@googlegroups.com, cris...@serpell.cl
You need to check the “Use the following Python interpret” box and enter the path of where pyomo is installed.

To test whether pyomo is installed in a given python distribution, you should be able to type (e.g.,) “/usr/bin/python” and then “import pyomo.environ” at the prompt. If the latter fails, then you don’t have the correct (pyomo-aware) python.

jpw

lbertolotti

unread,
Aug 23, 2015, 8:46:34 PM8/23/15
to Pyomo Forum, cris...@serpell.cl
from pyomo.environ import *

Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>

 
File "/usr/local/lib/python2.7/dist-packages/pyomo/environ/__init__.py", line 76, in <module>
    import_packages
()
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/environ/__init__.py", line 73, in import_packages
    pkg
.load()
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/__init__.py", line 13, in load
   
import pyomo.solvers.plugins.solvers
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/solvers/__init__.py", line 16, in <module>
   
import pyomo.solvers.plugins.solvers.glpk_direct
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/solvers/glpk_direct.py", line 21, in <module>
   
from glpk import *
 
File "/usr/lib/python2.7/dist-packages/glpk/__init__.py", line 26, in <module>
   
from glpk_parser import *
 
File "/usr/lib/python2.7/dist-packages/glpk/glpk_parser.py", line 352, in <module>
    yacc
.yacc(write_tables=0, debug=0)
 
File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 3244, in yacc
    read_signature
= lr.read_table(tabmodule)
 
File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 1967, in read_table
   
if parsetab._tabversion != __tabversion__:
AttributeError: 'module' object has no attribute '_tabversion'

lbertolotti

unread,
Aug 23, 2015, 8:53:43 PM8/23/15
to Pyomo Forum, cris...@serpell.cl
Can you figure out what's wrong here?

David Woodruff

unread,
Aug 23, 2015, 9:00:35 PM8/23/15
to pyomo...@googlegroups.com
No. I am not able reproduce the error.
At a minimum I would need to know what version of pyomo you have
pyomo --version
and I would need some context (can you send a small script that exhibits this error or let me know what command caused this error?)
  Dave


Message has been deleted

lbertolotti

unread,
Aug 24, 2015, 10:11:00 AM8/24/15
to Pyomo Forum, dlwoo...@ucdavis.edu
From Ubuntu terminal:

lucas@lucas-K55VD:~$ sudo pip install pyomo
The directory '/home/lucas/.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.
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the '
pip install --upgrade pip' command.
The directory '
/home/lucas/.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.
Requirement already satisfied (use --upgrade to upgrade): pyomo in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): ply in /usr/local/lib/python2.7/dist-packages (from pyomo)
Requirement already satisfied (use --upgrade to upgrade): nose in /usr/local/lib/python2.7/dist-packages (from pyomo)
Requirement already satisfied (use --upgrade to upgrade): PyUtilib==5.1.3556 in /usr/local/lib/python2.7/dist-packages (from pyomo)
Requirement already satisfied (use --upgrade to upgrade): six>=1.6.1 in /usr/local/lib/python2.7/dist-packages (from pyomo)
lucas@lucas
-K55VD:~$ pyomo --version
Traceback (most recent call last):

 
File "/usr/local/bin/pyomo", line 11, in <module>
    sys
.exit(main())
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/scripting/pyomo_main.py", line 33, in main
   
import pyomo.environ
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/environ/__init__.py", line 76, in <module>

    import_packages
()
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/environ/__init__.py", line 73, in import_packages
    pkg
.load()
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/__init__.py", line 13, in load
   
import pyomo.solvers.plugins.solvers
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/solvers/__init__.py", line 16, in <module>
   
import pyomo.solvers.plugins.solvers.glpk_direct
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/solvers/glpk_direct.py", line 21, in <module>
   
from glpk import *
 
File "/usr/lib/python2.7/dist-packages/glpk/__init__.py", line 26, in <module>
   
from glpk_parser import *
 
File "/usr/lib/python2.7/dist-packages/glpk/glpk_parser.py", line 352, in <module>
    yacc
.yacc(write_tables=0, debug=0)
 
File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 3244, in yacc
    read_signature
= lr.read_table(tabmodule)
 
File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 1967, in read_table
   
if parsetab._tabversion != __tabversion__:
AttributeError: 'module' object has no attribute '_tabversion'

lucas@lucas
-K55VD:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Siirola, John D

unread,
Aug 24, 2015, 11:06:20 AM8/24/15
to pyomo...@googlegroups.com

The exception is being thrown by the GLPK python package, and is not a strictly Pyomo error.  I have updated Pyomo trunk so that exceptions thrown by GLPK are not fatal to Pyomo.

Suggestions:

-          upgrade your GLPK package (pip install –upgrade glpk) [this may or may not fix the problem, depending on if GLPK has fixed their bug]

-          remove your GLPK python package (pip uninstall glpk)

-          find pyomo/solvers/plugins/solvers/glpk_direct.py, and edit line #21 to comment out “from glpk import *”

 

john

 

 

From: pyomo...@googlegroups.com [mailto:pyomo...@googlegroups.com]
Sent: Monday, August 24, 2015 8:03 AM
To: Pyomo Forum
Cc: dlwoo...@ucdavis.edu
Subject: Re: [EXTERNAL] Re: Python editors and pyomo

 

I was using spyder. This is Ubuntu terminal:

lucas@lucas-K55VD:~$ sudo pip install pyomo
The directory '/home/lucas/.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.
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the '
pip install --upgrade pip' command.
The directory '
/home/lucas/.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.
Requirement already satisfied (use --upgrade to upgrade): pyomo in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): ply in /usr/local/lib/python2.7/dist-packages (from pyomo)
Requirement already satisfied (use --upgrade to upgrade): nose in /usr/local/lib/python2.7/dist-packages (from pyomo)
Requirement already satisfied (use --upgrade to upgrade): PyUtilib==5.1.3556 in /usr/local/lib/python2.7/dist-packages (from pyomo)
Requirement already satisfied (use --upgrade to upgrade): six>=1.6.1 in /usr/local/lib/python2.7/dist-packages (from pyomo)


lucas@lucas
-K55VD:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> exit()


lucas@lucas
-K55VD:~$ sudo pip install pyomo
The directory '/home/lucas/.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.
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the '
pip install --upgrade pip' command.
The directory '
/home/lucas/.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.
Requirement already satisfied (use --upgrade to upgrade): pyomo in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): ply in /usr/local/lib/python2.7/dist-packages (from pyomo)
Requirement already satisfied (use --upgrade to upgrade): nose in /usr/local/lib/python2.7/dist-packages (from pyomo)
Requirement already satisfied (use --upgrade to upgrade): PyUtilib==5.1.3556 in /usr/local/lib/python2.7/dist-packages (from pyomo)
Requirement already satisfied (use --upgrade to upgrade): six>=1.6.1 in /usr/local/lib/python2.7/dist-packages (from pyomo)
lucas@lucas
-K55VD:~$ pyomo --version

Traceback (most recent call last):


 
File "/usr/local/bin/pyomo", line 11, in <module>
    sys
.exit(main())
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/scripting/pyomo_main.py", line 33, in main
   
import pyomo.environ


 
File "/usr/local/lib/python2.7/dist-packages/pyomo/environ/__init__.py", line 76, in <module>
    import_packages
()
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/environ/__init__.py", line 73, in import_packages
    pkg
.load()
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/__init__.py", line 13, in load
   
import pyomo.solvers.plugins.solvers
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/solvers/__init__.py", line 16, in <module>
   
import pyomo.solvers.plugins.solvers.glpk_direct
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/solvers/glpk_direct.py", line 21, in <module>
   
from glpk import *
 
File "/usr/lib/python2.7/dist-packages/glpk/__init__.py", line 26, in <module>
   
from glpk_parser import *
 
File "/usr/lib/python2.7/dist-packages/glpk/glpk_parser.py", line 352, in <module>
    yacc
.yacc(write_tables=0, debug=0)
 
File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 3244, in yacc
    read_signature
= lr.read_table(tabmodule)
 
File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 1967, in read_table
   
if parsetab._tabversion != __tabversion__:
AttributeError: 'module' object has no attribute '_tabversion'


lucas@lucas
-K55VD:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

lbertolotti

unread,
Aug 24, 2015, 3:04:09 PM8/24/15
to Pyomo Forum
The problem is glpk, do we need to contact the GNU project?

Siirola, John D

unread,
Aug 24, 2015, 3:29:10 PM8/24/15
to pyomo...@googlegroups.com

My read is that that exception is due to the GLPK python bindings, so they would be in the best position to fix it.

 

That said, Pyomo only invoked the GLPK python bindings through the GLPKDirect interface.  That interface was always somewhat experimental.  We ended up disabling it in Dec 2013: the code was not being actively tested in any of our test suites and no users appeared to be using it.  My recent commit to trunk prevents Pyomo from even attempting to import GLPK, which should isolate Pyomo from any further issues in the GLPK python bindings.

 

John

 

 

From: pyomo...@googlegroups.com [mailto:pyomo...@googlegroups.com]
Sent: Monday, August 24, 2015 1:04 PM
To: Pyomo Forum
Subject: Re: [EXTERNAL] Re: Python editors and pyomo

 

The problem is glpk, do we need to contact the GNU project?

--

lbertolotti

unread,
Aug 25, 2015, 3:33:47 PM8/25/15
to Pyomo Forum
https://software.sandia.gov/downloads/pub/pyomo/PyomoOnlineDocs.html#_pyomo_solver_interfaces
Continuing on the solver topic, can I get another MIP solver, beside GLPK to work with Pyomo?


Siirola, John D

unread,
Aug 25, 2015, 4:06:08 PM8/25/15
to pyomo...@googlegroups.com

I am not entirely sure what you are asking… we have several interfaces for GLPK, CBC, Gurobi, and CPLEX that are part of the core Pyomo distribution and are tested daily.  Are you trying to interface with those solvers, or with a different solver?

 

john

 

 

From: pyomo...@googlegroups.com [mailto:pyomo...@googlegroups.com]
Sent: Tuesday, August 25, 2015 1:34 PM
To: Pyomo Forum
Subject: Re: [EXTERNAL] Re: Python editors and pyomo

 


Continuing on the solver topic, can I get another MIP solver, beside GLPK to work with Pyomo?

lbertolotti

unread,
Aug 25, 2015, 4:33:29 PM8/25/15
to Pyomo Forum
You said to uninstall GLPK and that is what I did:


lucas@lucas-K55VD:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyomo.environ import *

now:

WARNING: DEPRECATION WARNING: the Model.create() method is deprecated.  Call Model.create_instance() if to create a concrete model from an abstract model.  You do not need to call Model.create() for a concrete model.
WARNING: "[base]/dist-packages/pyomo/solvers/plugins/solvers/GLPK_old.py", 68, executable
    Could not locate the 'glpsol' executable, which is required for solver 'glpk'

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile
    execfile(filename, namespace)
  File "/usr/local/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 78, in execfile
    builtins.execfile(filename, *where)
  File "/home/lucas/Assembly line/Askin_Standridge/costfunction.py", line 18, in <module>
    nstaz=nst(TC)
  File "line_balancing.py", line 78, in nst
    results = opt.solve( instance )
  File "/usr/local/lib/python2.7/dist-packages/pyomo/opt/base/solvers.py", line 432, in solve
    self.available(exception_flag=True)
  File "/usr/local/lib/python2.7/dist-packages/pyomo/opt/solver/shellcmd.py", line 52, in available
    raise ApplicationError(msg % self.name)
pyutilib.common._exceptions.ApplicationError: No executable found for solver 'glpk'

So, perhaps I need another solver? I was quite fond of glpk.

Siirola, John D

unread,
Aug 25, 2015, 4:44:43 PM8/25/15
to pyomo...@googlegroups.com

The only problem were the glpk python bindings, so you should only have had to uninstall the glpk python module (with pip uninstall glpk).  You should not have had to uninstall all of GLPK.  There are no known problems with GLPK binaries (and we regularly test against it).

 

If you are looking for another open source solver, I would start with either CBC (from COIN-OR) or SCIP (from ZIB).  Both are supported in Pyomo.

 

If you choose to use a different solver, you need to instantiate a different solver (somewhere in your script you probably have a line similar to “opt = SolverFactory(‘glpk’)” that needs to be changed).

 

john

 

 

 

From: pyomo...@googlegroups.com [mailto:pyomo...@googlegroups.com]
Sent: Tuesday, August 25, 2015 2:33 PM
To: Pyomo Forum
Subject: Re: [EXTERNAL] Re: Python editors and pyomo

 

You said to uninstall GLPK and that is what I did:

--

lbertolotti

unread,
Aug 25, 2015, 6:43:41 PM8/25/15
to Pyomo Forum
I see, can you add the preferred method of installation for pyomo solvers to the documentation?

I just went:

sudo apt-get install python-glpk
sudo apt-get install glpk-utils

lbertolotti

unread,
Aug 26, 2015, 1:50:50 PM8/26/15
to Pyomo Forum
    from pyomo.environ import SolverFactory
    opt = SolverFactory( 'cbc' )

Could not locate the 'cbc' executable, which is required for solver cbc
Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>
 
File "/usr/local/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile
    execfile
(filename, namespace)
 
File "/usr/local/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 78, in execfile
    builtins
.execfile(filename, *where)
 
File "/home/lucas/Assembly line/Askin_Standridge/costfunction.py", line 18, in <module>
    nstaz
=nst(TC)
 
File "line_balancing.py", line 78, in nst
    results
= opt.solve( instance )
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/opt/base/solvers.py", line 432, in solve
   
self.available(exception_flag=True)
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/opt/solver/shellcmd.py", line 52, in available
   
raise ApplicationError(msg % self.name)

pyutilib
.common._exceptions.ApplicationError: No executable found for solver 'cbc'


Michael Bynum

unread,
Aug 26, 2015, 2:08:47 PM8/26/15
to pyomo...@googlegroups.com
Is cbc installed and in your path?

Michael

lbertolotti

unread,
Aug 26, 2015, 2:31:50 PM8/26/15
to Pyomo Forum
pip uninstall glpk just gives me:

>>> from pyomo.environ import SolverFactory

Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>

 
File "/usr/local/lib/python2.7/dist-packages/pyomo/environ/__init__.py", line 76, in <module>
    import_packages
()
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/environ/__init__.py", line 73, in import_packages
    pkg
.load()
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/__init__.py", line 13, in load
   
import pyomo.solvers.plugins.solvers
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/solvers/__init__.py", line 16, in <module>
   
import pyomo.solvers.plugins.solvers.glpk_direct
 
File "/usr/local/lib/python2.7/dist-packages/pyomo/solvers/plugins/solvers/glpk_direct.py", line 21, in <module>
   
from glpk import *
 
File "/usr/lib/python2.7/dist-packages/glpk/__init__.py", line 26, in <module>
   
from glpk_parser import *
 
File "/usr/lib/python2.7/dist-packages/glpk/glpk_parser.py", line 352, in <module>
    yacc
.yacc(write_tables=0, debug=0)
 
File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 3244, in yacc
    read_signature
= lr.read_table(tabmodule)
 
File "/usr/local/lib/python2.7/dist-packages/ply/yacc.py", line 1967, in read_table
   
if parsetab._tabversion != __tabversion__:
AttributeError: 'module' object has no attribute '_tabversion'

I will take a look into installing other solvers in Ubuntu.

lbertolotti

unread,
Aug 27, 2015, 11:49:49 AM8/27/15
to pyomo...@googlegroups.com
cbc works like this:
  1. svn co https://projects.coin-or.org/svn/Cbc/stable/2.8 coin-Cbc
  2. cd coin-Cbc
  3. ./configure -C
  4. make
  5. make test
  6. make install
  1. lucas@lucas-K55VD:~$ python
    Python 2.7.6 (default, Jun 22 2015, 17:58:13)
    [GCC 4.8.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
  1. >>> from pyomo.environ import SolverFactory
    >>> opt = SolverFactory( 'cbc' )
lucas@lucas-K55VD:/usr/local/lib/python2.7/dist-packages/pyomo/core/tests/examples$ pyomo --solver=cbc pmedian4.py
WARNING
: converting to the 'pyomo solve' subcommand
[    0.00] Setting up Pyomo environment
[    0.00] Applying Pyomo preprocessing actions
[    0.00] Creating model
[    0.00] Applying solver
WARNING
: "[base]/dist-packages/pyomo/solvers/plugins/solvers/CBCplugin.py", 180, executable
   
Could not locate the 'cbc' executable, which is required for solver cbc
[    0.00] Pyomo Finished
ERROR
: Unexpected exception while running model:

   
No executable found for solver 'cbc'

lbertolotti

unread,
Aug 28, 2015, 10:42:02 AM8/28/15
to Pyomo Forum
For some reason I don't understand glpk is working now, but not cbc....

David Woodruff

unread,
Aug 28, 2015, 11:35:32 AM8/28/15
to pyomo...@googlegroups.com
Is cbc in your path? (i.e. can you cd to various directories and from each, can you run cbc from the command line?)

On Fri, Aug 28, 2015 at 7:42 AM, 'lbertolotti' via Pyomo Forum <pyomo...@googlegroups.com> wrote:
For some reason I don't understand glpk is working now, but not cbc....

--

lbertolotti

unread,
Aug 29, 2015, 10:52:27 AM8/29/15
to Pyomo Forum, dlwoo...@ucdavis.edu
sudo apt-get install coinor-cbc

solved it. As I said before, I think it is a good idea to add a preferred method of installation for each solver to the documentation. Hopefully this thread will be useful to others as well.
Reply all
Reply to author
Forward
0 new messages