Python3下email 安装报错 No module named 'cStringIO'
python 自动发送邮件需要用到 email模块,但是python3 在安装email包的时候出现了难以解决的问题。
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/ Collecting email Using cached https://pypi.tuna.tsinghua.edu.cn/packages/71/e7/816030d3b0426c130040bd068be62b9213357ed02896f5d9badcf46d1b5f/email-4.0.2.tar.gz (1.2 MB) DEPRECATION: The -b/--build/--build-dir/--build-directory option is deprecated and has no effect anymore. pip 21.1 will remove support for this functionality. A possible replacement is use the TMPDIR/TEMP/TMP environment variable, possibly combined with --no-clean. You can find discussion regarding this at https://github.com/pypa/pip/issues/8333. ERROR: Command errored out with exit status 1: command: 'F:\pycharm_data\venv\Scripts\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\TEMP\\pip-install-_69p8qeo\\email_ac83a28998054da4a3d65e4e3d48ea7a\\setup.py'"'"'; __file__='"'"'C:\\TEMP\\pip-install-_69p8qeo\\email_ac83a28998054da4a3d65e4e3d48ea7a\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\TEMP\pip-pip-egg-info-0ziudvw8' cwd: C:\TEMP\pip-install-_69p8qeo\email_ac83a28998054da4a3d65e4e3d48ea7a\ Complete output (11 lines): Traceback (most recent call last): File "<string>", line 1, in <module> File "F:\pycharm_data\venv\lib\site-packages\setuptools\__init__.py", line 16, in <module> import setuptools.version File "F:\pycharm_data\venv\lib\site-packages\setuptools\version.py", line 1, in <module> import pkg_resources File "F:\pycharm_data\venv\lib\site-packages\pkg_resources\__init__.py", line 33, in <module> import email.parser File "C:\TEMP\pip-install-_69p8qeo\email_ac83a28998054da4a3d65e4e3d48ea7a\email\parser.py", line 10, in <module> from cStringIO import StringIO ModuleNotFoundError: No module named 'cStringIO' ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
搜寻了网上的答案,大致可以理解为python2可以这么安装,但是python3中没有 cStringIO 这个包,如果是单纯引用 StringIO 可以使用
from io import StringIO
但是这种方法没用,因为这是在安装的时候出现的,我试着修改
C:\TEMP\pip-install-_69p8qeo\email_ac83a28998054da4a3d65e4e3d48ea7a\email\parser.py
这一文件内容,但是由于是安装时出现的临时文件,所以并不能进行修改。
解决方法:
1.看到安装包的时候的第一行没有?
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/71/e7/816030d3b0426c130040bd068be62b9213357ed02896f5d9badcf46d1b5f/email-4.0.2.tar.gz (1.2 MB)
把这里面的地址复制到浏览器中,直接将这个gz压缩包下载下来;
2.将gz解压缩出来,这时候如果尝试使用
python setup.py install
发现报错,并没有什么用,所以接下来
解压后的文件:
压缩包的文件名应该是 email-4.0.2(版本号不同数字不同),打开文件夹后里面会有doc、email等文件夹和setup.py、testall.py等文件,这时候把email这个文件夹复制到电脑中python的lib/site-packages 文件夹中,然后就可以正常使用email这个包了;
直接将里面的email文件贴过去: