简体   繁体   中英

ImportError: can't import openpyxl

I'm working in Spyder with the Anaconda interpreter. Python version is 3.10.5. Tried installing openpyxl with both the Windows CMD and the Anaconda prompt and they are both telling me openpyxl is installed. But Spyder stills throws the same errors:

ModuleNotFoundError: No module named 'openpyxl'

ImportError: Missing optional dependency 'openpyxl'.  Use pip or conda to install openpyxl.

There is no other Python version installed on my PC. What should I do?

What is most likely happening is that Spyder is not using the correct Python interpreter. If you're launching Spyder from the Anaconda navigator, it doesn't take the env you launched it from in all cases.

Is the conda env where you installed openpyxl the one listed at the bottom of the Spyder window?

底部 Spyder 面板

If not, click it and chose the path to your python.exe file in the Anaconda env (example below).

Python 解释器的设置

So, I am not sure this technically qualifies for an answer but my problem was solved.

I solved the issue by uninstalling Anaconda and Spyder. I had installed Spyder first, then Anaconda which probably messed up the environments. The morale of the story: only install Anaconda and let it set up everything for you automatically.

Try below commands to reinstall openpyxl in both Anaconda & system.

pip uninstall openpyxl

python -m pip install openpyxl

or

python3 -m pip3 install openpyxl

verify by

pip3 show openpyxl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM