Home > Software design >  "No module named 'openpyxl'" after installing with pip3 in Python 3.10.5
"No module named 'openpyxl'" after installing with pip3 in Python 3.10.5

Time:12-13

I installed openpyxl from the command line with pip. I am trying to run the code:

import openpyxl
from openpxyl import Workbook

I get: ModuleNotFoundError: No module named 'openpyxl'. This happens even though openpyxl shows up in the list of installed packages that comes up with pip list.

What I have tried so far:

  1. Uninstalling and re-installing openpyxl with pip3. This question says that I should be able to use pip3 install openpyxl, but using that gets an ERROR: No matching distribution found for openpyxl. I was only able to get it to install if I used pip3 install --user openpyxl
  2. Confirming I have the most recent version of pip with pip install --upgrade pip.
  3. Confirmed that the location of the site package is listed with print(sys.path).
  4. Trying to manually add the location of the site package with:
sys.path.append("C:/Users/[myname]/AppData/Roaming/Python/Python310/site-packages/")

And with:

sys.path.append("C:/Users/[myname]/AppData/Roaming/Python/Python310/site-packages/openpyxl/")
  1. Confirming that I have no other versions of Python installed as in this question.
  2. Setting up a virtual environment, installing openpyxl with pip3 install openpxyl in that, activating the virtual environment, and then invoking the script from that environment.

All of the above result in the same error.

CodePudding user response:

It is workbook, not Workbook.

And the error is in this line: from openpyxl import workbook, not in import openpyxl line.

Also close your old terminal where you just installed the package.

Demo:

Just installed package in a terminal for you: screenshot

and in a new terminal (works!): terminal

  • Related