Home > database >  ModuleNotFoundError: No module named 'pyomo'
ModuleNotFoundError: No module named 'pyomo'

Time:11-06

I am trying to run a jupyter notebook with pyomo, but get this error when trying to import from pyomo.environ.


!sapt-get install -y -qq coinor-cbc

from pyomo.environ import *

E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

---------------------------------------------------------------------------

ModuleNotFoundError                       Traceback (most recent call last)
Cell In \[2\], line 2
1 get_ipython().system('apt-get install -y -qq coinor-cbc')
\----\> 2 from pyomo.environ import \*

ModuleNotFoundError: No module named 'pyomo'

I have already installed pyomo with the command !pip install Pyomo==5.7.1. It installs correctly -- I get the message Successfully installed PyUtilib-6.0.0 Pyomo-5.7.1 nose-1.3.7 ply-3.11 and when I check the version with !pyomo --version I get Pyomo 5.7.1 (CPython 3.8.10 on Linux 5.10.16.3-microsoft-standard-WSL2).

Does anyone know what is wrong? I've already taken a look at enter image description here

Terminal. This shows the framework that I'm currently using (and by default installing new modules into):

% which python3
/Library/Frameworks/Python.framework/Versions/3.11/bin/python3
% 

If this is the case, update your jupyter install with pip3 in the terminal:

% pip3 install --upgrade jupyter

Then log out and log back in, open a new notebook and re-check:

enter image description here

This should ensure that the modules you installed are in the same framework that jupyter is using.

  • Related