简体   繁体   English

如何修复“导入错误:没有名为 openpyxl 的模块”?

[英]How to fix 'ImportError: No module named openpyxl'?

I am using Python 2.7 and am trying to run a program with openpyxl to work with xlsx files.我正在使用 Python 2.7 并尝试使用 openpyxl 运行一个程序来处理 xlsx 文件。

In the first line of code:在第一行代码中:

from openpyxl import Workbook

I get the following error when I run the program from the CMD: ImportError: No module named openpyxl从 CMD 运行程序时出现以下错误: ImportError: No module named openpyxl

I used pip to install version 2.6.0, and if I try to install it again through pip it just says I have the latest version.我使用 pip 安装了 2.6.0 版,如果我尝试通过 pip 再次安装它,它只会说我有最新版本。

Unlike any other question like this that I found here, I am using an IDE called PyCharm which has an option of running the program I am currently editing inside PyCharm, and PyCharm actually recognizes openpyxl and runs great, so why won't it work in the CMD?与我在这里找到的任何其他类似问题不同,我使用的是一个名为 PyCharm 的 IDE,它可以选择运行我目前在 PyCharm 中编辑的程序,而 PyCharm 实际上识别 openpyxl 并且运行良好,那么为什么它不能在CMD?

If you have multiple versions of python installed it might be related to the version of python that's added to your system path.如果您安装了多个版本的 python,它可能与添加到系统路径中的 python 版本有关。

What I would suggest you do is check your system path and verify that indeed the python/pip you are using from the command line is 2.7.我建议您做的是检查您的系统路径并验证您从命令行使用的 python/pip 确实是 2.7。 The same thing applies for PyCharm.同样的事情也适用于 PyCharm。

If you need help inspecting your system variables on windows: Check this link out!如果您需要帮助检查 Windows 上的系统变量: 查看此链接!

This answer is for those who land in this page without having openpyxl installed.这个答案适用于那些在没有安装openpyxl情况下登陆这个页面的人。

run pip install openpyxl command in your terminal在终端中运行pip install openpyxl命令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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