早上好!
直到昨天我使用python 2.7并使用以下代码为我的脚本编写输出文件:
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
但现在我将我的代码升级到python 3.7,所以现在我需要使用importlib.reload
instead只是reload
。但是,在我的shell上键入sudo -H pip3 install importlib
会给我以下错误:
Collecting importlib
Using cached https://files.pythonhosted.org/packages/31/77/3781f65cafe55480b56914def99022a5d2965a4bb269655c89ef2f1de3cd/importlib-1.0.4.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 6, in <module>
import distutils.core
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 16, in <module>
from distutils.dist import Distribution
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 19, in <module>
from distutils.util import check_environ, strtobool, rfc822_escape
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/util.py", line 9, in <module>
import importlib.util
ModuleNotFoundError: No module named 'importlib.util'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-3cz_3d6n/importlib/
在寻找解决方案后,我也尝试升级setuptools,但这并没有解决我的问题。
提前谢谢了!
importlib
at PyPI是用于very old Python versions的过时包装。对于新版本的Python importlib
是a module from the standard library,您不需要安装它,它始终可用。