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文件貼過去: