原因是没有安装xlrd模块,
python编程语言要读取excel,必须要安装模块xlrd才能读取excel文件,
利用pip命令,安装xlrd包-> pip install xlrd,
新提示,安装xlrd模块前要先安装pip。
在WINDOWS中运行CMD,出现命令提示符黑窗口,输入命令:pip install xlrd(安装xlrd模块)
C:\Users\name>pip install xlrd
Requirement already satisfied: xlrd in c:\programdata\anaconda3\lib\site-packages (1.1.0)
You are using pip version 18.0, however version 19.2.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
安装的时候,出现了警告:
C:\Users\name>python -m pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 27kB/s
Installing collected packages: pip
Found existing installation: pip 18.0
Uninstalling pip-18.0:
Successfully uninstalled pip-18.0
Rolling back uninstall of pip
Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: 'C:\\ProgramData\\Anaconda3\\Lib\\site-packages\\pip\\__init__.py'
Consider using the `--user` option or check the permissions.
You are using pip version 18.0, however version 19.2.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
【解决方法】:在pip安装命令的install后面加 --user便可以解决。 【注意】每次开机都要重新做一遍。否则又说没加载模块。
C:\Users\****>python -m pip install --user --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 18.0
Uninstalling pip-18.0:
Successfully uninstalled pip-18.0
Successfully installed pip-19.2.3
C:\Users\****>pip install xlrd
Requirement already satisfied: xlrd in c:\programdata\anaconda3\lib\site-packages (1.1.0)
C:\Users\****>pip install xlwt
Requirement already satisfied: xlwt in c:\programdata\anaconda3\lib\site-packages (1.3.0)
在CMD下安装xlrd和xlwt成功了。
【但是!但是!注意!注意!】在PyCharm中仍然出现错误!
在PyCharm中调用xlrd模块仍出现 ModuleNotFoundError: No module named 'xlrd' 提示!
为什么会这样呢?根本原因是在PyCharm中根本未加载xlrd和xlwt等模块!
因此,要按下图程序加载:
(一)安装xlrd
(二)安装xlwt