TensorFlow2.1.0安装错误解决办法-wrapt错误和dll加载错误
程序员文章站
2022-06-05 22:11:06
...
我在安装TensorFlow2.1.0时,遇到了以下错误。自己百度了很多方法,但是都比较零散,于是我把自己的经历总结成这篇教程分享给大家,希望能够有所帮助。
1. wrapt安装错误
Building wheel for wrapt (setup.py) ... Error
ERROR: Command errored out with exit status 1:
command: 'C:\Users\57371\.conda\envs\TensorFlow2.0\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\57371\\AppData\\Local\\Temp\\pip-install-8sudd7fm\\wrapt\\setup.py'"'"'; __file__='"'"'C:\\Users\\57371\\AppData\\Local\\Temp\\pip-install-8sudd7fm\\wrapt\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\57371\AppData\Local\Temp\pip-wheel-cesdoy36' --python-tag cp37
cwd: C:\Users\57371\AppData\Local\Temp\pip-install-8sudd7fm\wrapt\
Complete output (59 lines):
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.7
creating build\lib.win-amd64-3.7\wrapt
copying src\wrapt\decorators.py -> build\lib.win-amd64-3.7\wrapt
copying src\wrapt\importer.py -> build\lib.win-amd64-3.7\wrapt
copying src\wrapt\wrappers.py -> build\lib.win-amd64-3.7\wrapt
copying src\wrapt\__init__.py -> build\lib.win-amd64-3.7\wrapt
running build_ext
building 'wrapt._wrappers' extension
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\57371\AppData\Local\Temp\pip-install-8sudd7fm\wrapt\setup.py", line 101, in <module>
run_setup(with_extensions=True)
File "C:\Users\57371\AppData\Local\Temp\pip-install-8sudd7fm\wrapt\setup.py", line 71, in run_setup
setup(**setup_kwargs_tmp)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\site-packages\wheel\bdist_wheel.py", line 192, in run
self.run_command('build')
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\57371\AppData\Local\Temp\pip-install-8sudd7fm\wrapt\setup.py", line 25, in run
build_ext.run(self)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\build_ext.py", line 340, in run
self.build_extensions()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\build_ext.py", line 449, in build_extensions
self._build_extensions_serial()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\build_ext.py", line 474, in _build_extensions_serial
self.build_extension(ext)
File "C:\Users\57371\AppData\Local\Temp\pip-install-8sudd7fm\wrapt\setup.py", line 31, in build_extension
build_ext.build_extension(self, ext)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\build_ext.py", line 534, in build_extension
depends=ext.depends)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\_msvccompiler.py", line 346, in compile
self.initialize()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\_msvccompiler.py", line 239, in initialize
vc_env = _get_vc_env(plat_spec)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\site-packages\setuptools\msvc.py", line 171, in msvc14_get_vc_env
return EnvironmentInfo(plat_spec, vc_min_ver=14.0).return_env()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\site-packages\setuptools\msvc.py", line 1620, in return_env
if self.vs_ver >= 14 and isfile(self.VCRuntimeRedist):
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\genericpath.py", line 30, in isfile
st = os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
----------------------------------------
ERROR: Failed building wheel for wrapt
Running setup.py clean for wrapt
Failed to build wrapt
Installing collected packages: wrapt
Running setup.py install for wrapt ... error
ERROR: Command errored out with exit status 1:
command: 'C:\Users\57371\.conda\envs\TensorFlow2.0\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\57371\\AppData\\Local\\Temp\\pip-install-8sudd7fm\\wrapt\\setup.py'"'"'; __file__='"'"'C:\\Users\\57371\\AppData\\Local\\Temp\\pip-install-8sudd7fm\\wrapt\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\57371\AppData\Local\Temp\pip-record-_mrif7cq\install-record.txt' --single-version-externally-managed --compile
cwd: C:\Users\57371\AppData\Local\Temp\pip-install-8sudd7fm\wrapt\
Complete output (61 lines):
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.7
creating build\lib.win-amd64-3.7\wrapt
copying src\wrapt\decorators.py -> build\lib.win-amd64-3.7\wrapt
copying src\wrapt\importer.py -> build\lib.win-amd64-3.7\wrapt
copying src\wrapt\wrappers.py -> build\lib.win-amd64-3.7\wrapt
copying src\wrapt\__init__.py -> build\lib.win-amd64-3.7\wrapt
running build_ext
building 'wrapt._wrappers' extension
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\57371\AppData\Local\Temp\pip-install-8sudd7fm\wrapt\setup.py", line 101, in <module>
run_setup(with_extensions=True)
File "C:\Users\57371\AppData\Local\Temp\pip-install-8sudd7fm\wrapt\setup.py", line 71, in run_setup
setup(**setup_kwargs_tmp)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\site-packages\setuptools\command\install.py", line 61, in run
return orig.install.run(self)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\install.py", line 545, in run
self.run_command('build')
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\57371\AppData\Local\Temp\pip-install-8sudd7fm\wrapt\setup.py", line 25, in run
build_ext.run(self)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\build_ext.py", line 340, in run
self.build_extensions()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\build_ext.py", line 449, in build_extensions
self._build_extensions_serial()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\build_ext.py", line 474, in _build_extensions_serial
self.build_extension(ext)
File "C:\Users\57371\AppData\Local\Temp\pip-install-8sudd7fm\wrapt\setup.py", line 31, in build_extension
build_ext.build_extension(self, ext)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\command\build_ext.py", line 534, in build_extension
depends=ext.depends)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\_msvccompiler.py", line 346, in compile
self.initialize()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\distutils\_msvccompiler.py", line 239, in initialize
vc_env = _get_vc_env(plat_spec)
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\site-packages\setuptools\msvc.py", line 171, in msvc14_get_vc_env
return EnvironmentInfo(plat_spec, vc_min_ver=14.0).return_env()
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\site-packages\setuptools\msvc.py", line 1620, in return_env
if self.vs_ver >= 14 and isfile(self.VCRuntimeRedist):
File "C:\Users\57371\.conda\envs\TensorFlow2.0\lib\genericpath.py", line 30, in isfile
st = os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\57371\.conda\envs\TensorFlow2.0\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\57371\\AppData\\Local\\Temp\\pip-install-8sudd7fm\\wrapt\\setup.py'"'"'; __file__='"'"'C:\\Users\\57371\\AppData\\Local\\Temp\\pip-install-8sudd7fm\\wrapt\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\57371\AppData\Local\Temp\pip-record-_mrif7cq\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.
经过检查发现,是wrapt模块不对,于是上了https://www.lfd.uci.edu/~gohlke/pythonlibs/#wrapt
网站上一看,发现最新的wrapt是基于python3.8版本的,而我的python只是3.7,所以出错了。于是手动下载3.7版本的wrapt进行安装,然后 pip install “whl文件下载路径+whl文件名”,例如:pip install "E:\wrapt-1.10.11-cp37-cp37m-win_amd64.whl"
显示安装成功,在执行TensorFlow的安装命令,没有报错,一次性安装成功。
2. dll加载错误
运行代码测试,发现还有问题。
这是因为缺失了相应的运行库,https://aka.ms/vs/16/release/vc_redist.x64.exe
在这里下载所有的2015-2019的运行库进行安装,然后再次import,还是有警告,但是仔细看第二句,如果你安装不是GPU版本,则可以忽略上述警告。
至此,TensorFlow2.1.0安装成功。输入pip list,可以看到已经有TensorFlow在里面了。
上一篇: 一文详解 LSTM 诗词生成