Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python doesn't find Pyomo

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?

like image 554
Tim Avatar asked Sep 26 '26 18:09

Tim


2 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.

like image 182
nir0s Avatar answered Sep 28 '26 09:09

nir0s


I would uninstall it via pip,

pip uninstall pyomo

and then reinstall it via conda.

conda install -c conda-forge pyomo 
like image 43
oakca Avatar answered Sep 28 '26 08:09

oakca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!