ImportError: Missing optional dependency 'openpyxl' still doesn't work after instllation

Viewed 21404

ubuntu 18.04, python3.8 and using pycharm.

Interpreter path in pychamr is correctly set.

while trying to read specific sheet in excel, using openpyxl it keeps on giving me ImportError. ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.

I've installed using pip3 install openpyxl and it say requirement is already satisfied. However when I run it again in pycharm it still outputs same error.

Requirement already satisfied: openpyxl mycomp/.local/lib/python3.8/site-packages (3.0.7)
Requirement already satisfied: et-xmlfile in mycomp/.local/lib/python3.8/site-packages (from openpyxl) (1.0.1)

My guess is since I am using venv it is not getting installed correctly in venv because when I look at the path upon install it is not where venv is.

When I do pip3 freeze on venv and after deactivating venv it looks like it has same installation.

4 Answers

for me worked typing the following inside an interactive session:

import pip
pip.main(["install", "openpyxl"])

What helped in my case: installing an additional optional library

pip install defusedxml

I ran into something similar because pandas is using this behind the scenes.

Clean your local python environment or create a fresh virtual environment to use from your IDE. Then if possible, try installing your modules in one pip command instead of on multiple lines.

# THIS, substitute pandas for whatever module is using openpyxl
pip install pandas openpyxl

# NOT THIS
pip install pandas
pip install openpyxl

# VERSIONS
pandas==1.4.3
openpyxl==3.0.10

Deleting venv and creating a new one fixed the issue.

previous venv had all dependencies as base which did not make sense. Maybe error on venv? I am curious to know if anyone knows.

Related