Python doesn't find Pyomo

Question:

I’m stumped on why Python won’t import pyomo. I can find the directory and see it is installed:

234:pyomo user$ pip show pyomo
Name: Pyomo
Version: 5.1.1
Summary: Pyomo: Python Optimization Modeling Objects
Home-page: http://pyomo.org
Author: William E. Hart
Author-email: [email protected]
License: BSD
Location: /Users/user/anaconda/lib/python2.7/site-packages
Requires: appdirs, PyUtilib, six, ply

And the directory is at the front of my $PYTHONPATH:

>>> import sys; print sys.path
['', '/Users/user/anaconda/lib/python2.7/site-packages/pyomo', '/Users/user/anaconda/lib/python2.7/site-packages', '/Users/user/anaconda/pkgs', '/Users/user/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages',  ... ] 

But I still can’t import pyomo:

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

What am I missing here?

Asked By: Tim

||

Answers:

You need to make sure you’re trying to import from the same interpreter you’re using when you’re running pip show.

When these things happen (and they tend to), it’s always good to to try and run which python (assuming you’re on linux/osx) to verify that it is the python you’re intending to use.

Answered By: nir0s

I would uninstall it via pip,

pip uninstall pyomo

and then reinstall it via conda.

conda install -c conda-forge pyomo 
Answered By: oakca

Check if you have pandas installed. If not,

pip install pandas

then

pip install pyomo

this works for me

Answered By: Mimi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.