安装pytorch报错及解决

人工智能150

环境,win10,64位,Anaconda4.10.3,Cuda 9.2.148,cudnn应该为v7.4.2.24

其中在Anaconda中好像安装tensorflow-gpu 1.9 ,python3.7 64位,及32位虚拟python环境。

github 上找的此程序代码所需环境为3.5python

程序地址:

GitHub - MichalDanielDobrzanski/DeepLearningPython: neuralnetworksanddeeplearning.com integrated scripts for Python 3.5.2 and Theano with CUDA support

于是想再配置一个Python3.5的环境。现在安装了python3.5,想安装一个对应版本的tensorflow。网上查了说对应版本为tensorflow1.1.于是尝试安装此版本。

尝试命令:并指定其版本

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==1.1

报错为安装pytorch报错及解决

尝试此链接中的程序安装tensorflow1.0:python - Unable to install tensorflow=1.0.0 - Stack Overflow

命令如下:

安装pytorch报错及解决

结果显示:

安装pytorch报错及解决

同时新问题出现了,tensorflow 不可用,并报错了,报错显示如上图。猜测可能版本不一样导致的。因此查找了具体版本和所能用的tensorflow。

版本匹配,及其命令具体如下:link:

tensorflow-gpu1.X版本和2.X版本详细安装流程(使用了清华的镜像源,包括cuda和cudnn安装)_一头特立独行的驴的博客-CSDN博客_cudnn镜像源

安装pytorch报错及解决

在纠错过程中,用到cuda的一些命令如下:

#cuda 常用命令
cd .. #返回上一目录,直到当前盘的根目录
D:   #直接输入盘符,切换目录
cd anaconda/envs/   #cd 加路径,可以切换到想去的路径

nvcc -V #查看 cuda 版本
conda info --envs  #查看conda 虚拟环境,结果的第一列为环境名
activate python37  #进入对应的虚拟环境,其中python37为环境名
python -V          #查看当前python版本

然后尝试安装tensorflow 1.5.0:报错:

安装pytorch报错及解决

尝试tensorlow 1.6.0版本,报错:总结为grpcio这个东西版本不对:然后根据链接:python 2.7 - Unable to install grpcio using pip install grpcio - Stack Overflow

进行跟新等操作。

Failed building wheel for grpcio
  Running setup.py clean for grpcio
  Running setup.py bdist_wheel for html5lib ... done
  Stored in directory: C:\Users\11327\AppData\Local\pip\Cache\wheels\11\b5\a5\84223095b1b4720df984fcea6e033580349dafca6034f2e491
Successfully built termcolor html5lib
Failed to build grpcio
Installing collected packages: astor, absl-py, werkzeug, html5lib, bleach, zipp, importlib-metadata, markdown, tensorboard, termcolor, grpcio, gast, tensorflow-gpu
  Running setup.py install for grpcio ... error
    Complete output from command D:\anaconda\envs\tf1.0\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\11327\\AppData\\Local\\Temp\\pip-install-bwp3jkup\\grpcio\\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\11327\AppData\Local\Temp\pip-record-xp9hkq40\install-record.txt --single-version-externally-managed --compile:
    ASM Builds for BoringSSL currently not supported on: win-amd64
    Cython-generated files are missing...

    We could not find Cython. Setup may take 10-20 minutes.

    running install
    running build
    running build_py
    running build_project_metadata
    creating python_build
    creating python_build\lib.win-amd64-3.5
    creating python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_auth.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_channel.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_common.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_compression.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_grpcio_metadata.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_interceptor.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_plugin_wrapping.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_runtime_protos.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_server.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_simple_stubs.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\_utilities.py -> python_build\lib.win-amd64-3.5\grpc
    copying src\python\grpcio\grpc\__init__.py -> python_build\lib.win-amd64-3.5\grpc
    creating python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\_base_call.py -> python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\_base_channel.py -> python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\_base_server.py -> python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\_call.py -> python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\_channel.py -> python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\_interceptor.py -> python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\_metadata.py -> python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\_server.py -> python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\_typing.py -> python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\_utils.py -> python_build\lib.win-amd64-3.5\grpc\aio
    copying src\python\grpcio\grpc\aio\__init__.py -> python_build\lib.win-amd64-3.5\grpc\aio
    creating python_build\lib.win-amd64-3.5\grpc\beta
    copying src\python\grpcio\grpc\beta\implementations.py -> python_build\lib.win-amd64-3.5\grpc\beta
    copying src\python\grpcio\grpc\beta\interfaces.py -> python_build\lib.win-amd64-3.5\grpc\beta
    copying src\python\grpcio\grpc\beta\utilities.py -> python_build\lib.win-amd64-3.5\grpc\beta
    copying src\python\grpcio\grpc\beta\_client_adaptations.py -> python_build\lib.win-amd64-3.5\grpc\beta
    copying src\python\grpcio\grpc\beta\_metadata.py -> python_build\lib.win-amd64-3.5\grpc\beta
    copying src\python\grpcio\grpc\beta\_server_adaptations.py -> python_build\lib.win-amd64-3.5\grpc\beta
    copying src\python\grpcio\grpc\beta\__init__.py -> python_build\lib.win-amd64-3.5\grpc\beta
    creating python_build\lib.win-amd64-3.5\grpc\experimental
    copying src\python\grpcio\grpc\experimental\gevent.py -> python_build\lib.win-amd64-3.5\grpc\experimental
    copying src\python\grpcio\grpc\experimental\session_cache.py -> python_build\lib.win-amd64-3.5\grpc\experimental
    copying src\python\grpcio\grpc\experimental\__init__.py -> python_build\lib.win-amd64-3.5\grpc\experimental
    creating python_build\lib.win-amd64-3.5\grpc\framework
    copying src\python\grpcio\grpc\framework\__init__.py -> python_build\lib.win-amd64-3.5\grpc\framework
    creating python_build\lib.win-amd64-3.5\grpc\_cython
    copying src\python\grpcio\grpc\_cython\__init__.py -> python_build\lib.win-amd64-3.5\grpc\_cython
    creating python_build\lib.win-amd64-3.5\grpc\experimental\aio
    copying src\python\grpcio\grpc\experimental\aio\__init__.py -> python_build\lib.win-amd64-3.5\grpc\experimental\aio
    creating python_build\lib.win-amd64-3.5\grpc\framework\common
    copying src\python\grpcio\grpc\framework\common\cardinality.py -> python_build\lib.win-amd64-3.5\grpc\framework\common
    copying src\python\grpcio\grpc\framework\common\style.py -> python_build\lib.win-amd64-3.5\grpc\framework\common
    copying src\python\grpcio\grpc\framework\common\__init__.py -> python_build\lib.win-amd64-3.5\grpc\framework\common
    creating python_build\lib.win-amd64-3.5\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\abandonment.py -> python_build\lib.win-amd64-3.5\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\callable_util.py -> python_build\lib.win-amd64-3.5\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\future.py -> python_build\lib.win-amd64-3.5\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\logging_pool.py -> python_build\lib.win-amd64-3.5\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\stream.py -> python_build\lib.win-amd64-3.5\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\stream_util.py -> python_build\lib.win-amd64-3.5\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\__init__.py -> python_build\lib.win-amd64-3.5\grpc\framework\foundation
    creating python_build\lib.win-amd64-3.5\grpc\framework\interfaces
    copying src\python\grpcio\grpc\framework\interfaces\__init__.py -> python_build\lib.win-amd64-3.5\grpc\framework\interfaces
    creating python_build\lib.win-amd64-3.5\grpc\framework\interfaces\base
    copying src\python\grpcio\grpc\framework\interfaces\base\base.py -> python_build\lib.win-amd64-3.5\grpc\framework\interfaces\base
    copying src\python\grpcio\grpc\framework\interfaces\base\utilities.py -> python_build\lib.win-amd64-3.5\grpc\framework\interfaces\base
    copying src\python\grpcio\grpc\framework\interfaces\base\__init__.py -> python_build\lib.win-amd64-3.5\grpc\framework\interfaces\base
    creating python_build\lib.win-amd64-3.5\grpc\framework\interfaces\face
    copying src\python\grpcio\grpc\framework\interfaces\face\face.py -> python_build\lib.win-amd64-3.5\grpc\framework\interfaces\face
    copying src\python\grpcio\grpc\framework\interfaces\face\utilities.py -> python_build\lib.win-amd64-3.5\grpc\framework\interfaces\face
    copying src\python\grpcio\grpc\framework\interfaces\face\__init__.py -> python_build\lib.win-amd64-3.5\grpc\framework\interfaces\face
    creating python_build\lib.win-amd64-3.5\grpc\_cython\_cygrpc
    copying src\python\grpcio\grpc\_cython\_cygrpc\__init__.py -> python_build\lib.win-amd64-3.5\grpc\_cython\_cygrpc
    creating python_build\lib.win-amd64-3.5\grpc\_cython\_credentials
    copying src\python\grpcio\grpc\_cython\_credentials\roots.pem -> python_build\lib.win-amd64-3.5\grpc\_cython\_credentials
    running build_ext
    Non-fatal exception:Traceback (most recent call last):
      File "C:\Users\11327\AppData\Local\Temp\pip-install-bwp3jkup\grpcio\src\python\grpcio\commands.py", line 239, in compiler_ok_with_extra_std
        stderr=subprocess.PIPE)
      File "D:\anaconda\envs\tf1.0\lib\subprocess.py", line 676, in __init__
        restore_signals, start_new_session)
      File "D:\anaconda\envs\tf1.0\lib\subprocess.py", line 957, in _execute_child
        startupinfo)
    FileNotFoundError: [WinError 2] 系统找不到指定的文件。

    Cython-generated files are missing...

    Compiling src\python\grpcio\grpc/_cython/cygrpc.pyx because it changed.

    [1/1] Cythonizing src\python\grpcio\grpc/_cython/cygrpc.pyx
    c:\users\11327\appdata\local\temp\pip-install-bwp3jkup\grpcio\.eggs\cython-3.0.0a10-py3.5.egg\Cython\Compiler\Main.py:346: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: C:\Users\11327\AppData\Local\Temp\pip-install-bwp3jkup\grpcio\src\python\grpcio\grpc\_cython\cygrpc.pxd
      tree = Parsing.p_module(s, pxd, full_module_name)
    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:20:0: Dotted filenames ('_cygrpc/arguments.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:21:0: Dotted filenames ('_cygrpc/call.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:22:0: Dotted filenames ('_cygrpc/channel.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:23:0: Dotted filenames ('_cygrpc/credentials.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:24:0: Dotted filenames ('_cygrpc/completion_queue.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:25:0: Dotted filenames ('_cygrpc/event.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:26:0: Dotted filenames ('_cygrpc/metadata.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:27:0: Dotted filenames ('_cygrpc/operation.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:28:0: Dotted filenames ('_cygrpc/propagation_bits.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:29:0: Dotted filenames ('_cygrpc/records.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:30:0: Dotted filenames ('_cygrpc/security.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:31:0: Dotted filenames ('_cygrpc/server.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:32:0: Dotted filenames ('_cygrpc/tag.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:33:0: Dotted filenames ('_cygrpc/time.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:34:0: Dotted filenames ('_cygrpc/vtable.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:35:0: Dotted filenames ('_cygrpc/_hooks.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:37:0: Dotted filenames ('_cygrpc/iomgr.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:39:0: Dotted filenames ('_cygrpc/grpc_gevent.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:45:0: Dotted filenames ('_cygrpc/aio/completion_queue.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:46:0: Dotted filenames ('_cygrpc/aio/rpc_status.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:47:0: Dotted filenames ('_cygrpc/aio/grpc_aio.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:48:0: Dotted filenames ('_cygrpc/aio/callback_common.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:49:0: Dotted filenames ('_cygrpc/aio/call.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:50:0: Dotted filenames ('_cygrpc/aio/channel.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pxd:51:0: Dotted filenames ('_cygrpc/aio/server.pxd.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:39:0: Dotted filenames ('_cygrpc/grpc_string.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:40:0: Dotted filenames ('_cygrpc/arguments.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:41:0: Dotted filenames ('_cygrpc/call.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:42:0: Dotted filenames ('_cygrpc/channel.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:43:0: Dotted filenames ('_cygrpc/channelz.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:44:0: Dotted filenames ('_cygrpc/csds.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:45:0: Dotted filenames ('_cygrpc/credentials.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:46:0: Dotted filenames ('_cygrpc/completion_queue.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:47:0: Dotted filenames ('_cygrpc/event.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:48:0: Dotted filenames ('_cygrpc/metadata.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:49:0: Dotted filenames ('_cygrpc/operation.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:50:0: Dotted filenames ('_cygrpc/propagation_bits.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:51:0: Dotted filenames ('_cygrpc/records.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:52:0: Dotted filenames ('_cygrpc/security.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:53:0: Dotted filenames ('_cygrpc/server.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:54:0: Dotted filenames ('_cygrpc/tag.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:55:0: Dotted filenames ('_cygrpc/time.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:56:0: Dotted filenames ('_cygrpc/vtable.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:57:0: Dotted filenames ('_cygrpc/_hooks.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:59:0: Dotted filenames ('_cygrpc/iomgr.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:61:0: Dotted filenames ('_cygrpc/grpc_gevent.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:63:0: Dotted filenames ('_cygrpc/thread.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:66:4: Dotted filenames ('_cygrpc/fork_windows.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:71:0: Dotted filenames ('_cygrpc/aio/common.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:72:0: Dotted filenames ('_cygrpc/aio/rpc_status.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:73:0: Dotted filenames ('_cygrpc/aio/completion_queue.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:74:0: Dotted filenames ('_cygrpc/aio/callback_common.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:75:0: Dotted filenames ('_cygrpc/aio/grpc_aio.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:76:0: Dotted filenames ('_cygrpc/aio/call.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:77:0: Dotted filenames ('_cygrpc/aio/channel.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    warning: src\python\grpcio\grpc\_cython\cygrpc.pyx:78:0: Dotted filenames ('_cygrpc/aio/server.pyx.pxi') are deprecated. Please use the normal Python package directory layout.

    building 'grpc._cython.cygrpc' extension
    Traceback (most recent call last):
      File "C:\Users\11327\AppData\Local\Temp\pip-install-bwp3jkup\grpcio\src\python\grpcio\commands.py", line 285, in build_extensions
        build_ext.build_ext.build_extensions(self)
      File "D:\anaconda\envs\tf1.0\lib\distutils\command\build_ext.py", line 448, in build_extensions
        self._build_extensions_serial()
      File "D:\anaconda\envs\tf1.0\lib\distutils\command\build_ext.py", line 473, in _build_extensions_serial
        self.build_extension(ext)
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\command\build_ext.py", line 199, in build_extension
        _build_ext.build_extension(self, ext)
      File "D:\anaconda\envs\tf1.0\lib\distutils\command\build_ext.py", line 533, in build_extension
        depends=ext.depends)
      File "D:\anaconda\envs\tf1.0\lib\distutils\_msvccompiler.py", line 304, in compile
        self.initialize()
      File "D:\anaconda\envs\tf1.0\lib\distutils\_msvccompiler.py", line 197, in initialize
        vc_env = _get_vc_env(plat_spec)
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\msvc.py", line 185, in msvc14_get_vc_env
        return EnvironmentInfo(plat_spec, vc_min_ver=14.0).return_env()
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\msvc.py", line 1227, in return_env
        [self.VCIncludes,
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\msvc.py", line 876, in VCIncludes
        return [os.path.join(self.si.VCInstallDir, 'Include'),
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\msvc.py", line 555, in VCInstallDir
        raise distutils.errors.DistutilsPlatformError(msg)
    distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\11327\AppData\Local\Temp\pip-install-bwp3jkup\grpcio\setup.py", line 542, in <module>
        cmdclass=COMMAND_CLASS,
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\__init__.py", line 140, in setup
        return distutils.core.setup(**attrs)
      File "D:\anaconda\envs\tf1.0\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "D:\anaconda\envs\tf1.0\lib\distutils\dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "D:\anaconda\envs\tf1.0\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "D:\anaconda\envs\tf1.0\lib\distutils\command\install.py", line 539, in run
        self.run_command('build')
      File "D:\anaconda\envs\tf1.0\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "D:\anaconda\envs\tf1.0\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "D:\anaconda\envs\tf1.0\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "D:\anaconda\envs\tf1.0\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "D:\anaconda\envs\tf1.0\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\command\build_ext.py", line 78, in run
        _build_ext.run(self)
      File "D:\anaconda\envs\tf1.0\lib\distutils\command\build_ext.py", line 339, in run
        self.build_extensions()
      File "C:\Users\11327\AppData\Local\Temp\pip-install-bwp3jkup\grpcio\src\python\grpcio\commands.py", line 288, in build_extensions
        support.diagnose_build_ext_error(self, error, formatted_exception)
      File "C:\Users\11327\AppData\Local\Temp\pip-install-bwp3jkup\grpcio\src\python\grpcio\support.py", line 115, in diagnose_build_ext_error
        "backtrace).\n\n{}".format(formatted))
    commands.CommandError:

    We could not diagnose your build failure. If you are unable to proceed, please file an issue at http://www.github.com/grpc/grpc with `[Python install]` in the title; please attach the whole log (including everything that may have appeared above the Python backtrace).

    Traceback (most recent call last):
      File "C:\Users\11327\AppData\Local\Temp\pip-install-bwp3jkup\grpcio\src\python\grpcio\commands.py", line 285, in build_extensions
        build_ext.build_ext.build_extensions(self)
      File "D:\anaconda\envs\tf1.0\lib\distutils\command\build_ext.py", line 448, in build_extensions
        self._build_extensions_serial()
      File "D:\anaconda\envs\tf1.0\lib\distutils\command\build_ext.py", line 473, in _build_extensions_serial
        self.build_extension(ext)
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\command\build_ext.py", line 199, in build_extension
        _build_ext.build_extension(self, ext)
      File "D:\anaconda\envs\tf1.0\lib\distutils\command\build_ext.py", line 533, in build_extension
        depends=ext.depends)
      File "D:\anaconda\envs\tf1.0\lib\distutils\_msvccompiler.py", line 304, in compile
        self.initialize()
      File "D:\anaconda\envs\tf1.0\lib\distutils\_msvccompiler.py", line 197, in initialize
        vc_env = _get_vc_env(plat_spec)
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\msvc.py", line 185, in msvc14_get_vc_env
        return EnvironmentInfo(plat_spec, vc_min_ver=14.0).return_env()
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\msvc.py", line 1227, in return_env
        [self.VCIncludes,
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\msvc.py", line 876, in VCIncludes
        return [os.path.join(self.si.VCInstallDir, 'Include'),
      File "D:\anaconda\envs\tf1.0\lib\site-packages\setuptools\msvc.py", line 555, in VCInstallDir
        raise distutils.errors.DistutilsPlatformError(msg)
    distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/

    ----------------------------------------
Command "D:\anaconda\envs\tf1.0\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\11327\\AppData\\Local\\Temp\\pip-install-bwp3jkup\\grpcio\\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\11327\AppData\Local\Temp\pip-record-xp9hkq40\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\11327\AppData\Local\Temp\pip-install-bwp3jkup\grpcio\
You are using pip version 10.0.1, however version 20.3.4 is available.

You should consider upgrading via the 'python -m pip install --upgrade pip' command.</module></module></string>

出错:仅选取最后几行(报错实在太多了)

 File "C:\Users\11327\AppData\Local\Temp\pip-install-v1o1zqw3\grpcio\src\python\grpcio\commands.py", line 288, in build_extensions
        support.diagnose_build_ext_error(self, error, formatted_exception)
      File "C:\Users\11327\AppData\Local\Temp\pip-install-v1o1zqw3\grpcio\src\python\grpcio\support.py", line 117, in diagnose_build_ext_error
        diagnostic(build_ext, error)
      File "C:\Users\11327\AppData\Local\Temp\pip-install-v1o1zqw3\grpcio\src\python\grpcio\support.py", line 97, in diagnose_attribute_error
        "We expect a missing `_needs_stub` attribute from older versions of "
    commands.CommandError: We expect a missing `_needs_stub` attribute from older versions of setuptools. Consider upgrading setuptools.

    ----------------------------------------
Command "D:\anaconda\envs\tf1.0\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\11327\\AppData\\Local\\Temp\\pip-install-v1o1zqw3\\grpcio\\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\11327\AppData\Local\Temp\pip-record-jgypeq1u\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\11327\AppData\Local\Temp\pip-install-v1o1zqw3\grpcio\

然后安装其指定prpcio==1.36.1

pip3 install --no-cache-dir  --force-reinstall -Iv grpcio==1.36.1

然后就安装成功了,

tensorflow 1.6.0安装成功,但是 依旧不能用(好傻呀这个问题),

Installing collected packages: gast, tensorflow-gpu
Successfully installed gast-0.5.3 tensorflow-gpu-1.6.0
You are using pip version 10.0.1, however version 20.3.4 is available.

You should consider upgrading via the 'python -m pip install --upgrade pip' command.

(tf1.0) D:\anaconda\envs\tf1.0>import tensorflow as tf
'import' is not recognized as an internal or external command,
operable program or batch file.

要切换到python环境里用tensorflow,上述是在a command line里面运行

所以切换到python,试试tensorflow,报错如下,(这个错误似曾相识)

>>> import tensorflow as tf
D:\anaconda\envs\tf1.0\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.

  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
D:\anaconda\envs\tf1.0\lib\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.

  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
D:\anaconda\envs\tf1.0\lib\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.

  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
D:\anaconda\envs\tf1.0\lib\site-packages\tensorflow\python\framework\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.

  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
D:\anaconda\envs\tf1.0\lib\site-packages\tensorflow\python\framework\dtypes.py:521: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.

  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
D:\anaconda\envs\tf1.0\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.

  np_resource = np.dtype([("resource", np.ubyte, 1)])

回想之前用python3.7 tensorflow 1.9直接运行数字识别程序时出错:

runfile('E:/work/DeepLearningPython-master/test.py', wdir='E:/work/DeepLearningPython-master')
WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
D:\anaconda\envs\python37\lib\site-packages\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
  warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.

WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

Trying to run under a GPU.  If this is not desired, then modify network3.py
to set the GPU flag to False.

D:\anaconda\envs\python37\lib\site-packages\theano\tensor\nnet\conv.py:98: UserWarning: theano.tensor.nnet.conv.conv2d is deprecated. Use theano.tensor.nnet.conv2d instead.

  warnings.warn("theano.tensor.nnet.conv.conv2d is deprecated."
Training mini-batch number 0
D:\anaconda\envs\python37\lib\site-packages\theano\tensor\signal\pool.py:574: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.

  yk[[region_slices[i][r[i]] for i in xrange(nd)]])
D:\anaconda\envs\python37\lib\site-packages\theano\tensor\signal\pool.py:574: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.

  yk[[region_slices[i][r[i]] for i in xrange(nd)]])
D:\anaconda\envs\python37\lib\site-packages\theano\tensor\signal\pool.py:574: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.

  yk[[region_slices[i][r[i]] for i in xrange(nd)]])
D:\anaconda\envs\python37\lib\site-packages\theano\tensor\signal\pool.py:574: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.

  yk[[region_slices[i][r[i]] for i in xrange(nd)]])
D:\anaconda\envs\python37\lib\site-packages\theano\tensor\signal\pool.py:574: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.

  yk[[region_slices[i][r[i]] for i in xrange(nd)]])
D:\anaconda\envs\python37\lib\site-packages\theano\tensor\signal\pool.py:574: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.

  yk[[region_slices[i][r[i]] for i in xrange(nd)]])
D:\anaconda\envs\python37\lib\site-packages\theano\tensor\signal\pool.py:574: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.

  yk[[region_slices[i][r[i]] for i in xrange(nd)]])
D:\anaconda\envs\python37\lib\site-packages\theano\tensor\signal\pool.py:574: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.

  yk[[region_slices[i][r[i]] for i in xrange(nd)]])
Traceback (most recent call last):

  File "C:\Users\11327\AppData\Local\Temp/ipykernel_16896/1828017625.py", line 1, in <module>
    runfile('E:/work/DeepLearningPython-master/test.py', wdir='E:/work/DeepLearningPython-master')

  File "D:\anaconda\envs\python37\lib\site-packages\debugpy\_vendored\pydevd\_pydev_bundle\pydev_umd.py", line 167, in runfile
    execfile(filename, namespace)

  File "D:\anaconda\envs\python37\lib\site-packages\debugpy\_vendored\pydevd\_pydev_imps\_pydev_execfile.py", line 25, in execfile
    exec(compile(contents + "\n", file, 'exec'), glob, loc)

  File "E:/work/DeepLearningPython-master/test.py", line 210, in <module>
    net.SGD(training_data, 60, mini_batch_size, 0.03, validation_data, test_data, lmbda=0.1)

  File "E:\work\DeepLearningPython-master\network3.py", line 163, in SGD
    cost_ij = train_mb(minibatch_index)

  File "D:\anaconda\envs\python37\lib\site-packages\theano\compile\function_module.py", line 903, in __call__
    self.fn() if output_subset is None else\

  File "D:\anaconda\envs\python37\lib\site-packages\theano\gof\vm.py", line 301, in __call__
    thunk()

  File "D:\anaconda\envs\python37\lib\site-packages\theano\gof\op.py", line 892, in rval
    r = p(n, [x[0] for x in i], o)

  File "D:\anaconda\envs\python37\lib\site-packages\theano\tensor\elemwise.py", line 790, in perform
    variables = ufunc(*ufunc_args, **ufunc_kwargs)

  File "D:\anaconda\envs\python37\lib\site-packages\theano\scalar\basic.py", line 4023, in impl
    self.perform(None, inputs, output_storage)

  File "D:\anaconda\envs\python37\lib\site-packages\theano\scalar\basic.py", line 4019, in perform
    storage[0] = impl(inputs)

  File "D:\anaconda\envs\python37\lib\site-packages\theano\scalar\basic.py", line 3891, in f
    return node.op.impl(*[p(inputs) for p in producers])

  File "D:\anaconda\envs\python37\lib\site-packages\theano\scalar\basic.py", line 1748, in impl
    return np.product(inputs)

  File "<__array_function__ internals>", line 6, in product

  File "D:\anaconda\envs\python37\lib\site-packages\numpy\core\fromnumeric.py", line 3751, in product
    return prod(*args, **kwargs)

  File "<__array_function__ internals>", line 6, in prod

  File "D:\anaconda\envs\python37\lib\site-packages\numpy\core\fromnumeric.py", line 3052, in prod
    keepdims=keepdims, initial=initial, where=where)

KeyboardInterrupt</__array_function__></__array_function__></module></module>

见下一篇博文,安装pytorch报错及解决。END

Original: https://blog.csdn.net/huachuchengzhang/article/details/122504292
Author: SuperLuu7
Title: 安装pytorch报错及解决



相关阅读

Title: 简洁优美的深度学习包-bert4keras

在鹅厂实习阶段,follow苏神(科学空间)的博客,启发了idea,成功改进了线上的一款模型。想法产出和实验进展很大一部分得益于苏神设计的bert4keras,清晰轻量、基于keras,可以很简洁的实现bert,同时附上了很多易读的example,对nlp新手及其友好!本文推荐几篇基于bert4keras的项目,均来自苏神,对新手入门bert比较合适~

  • tokenizer:分词器,主要方法:encode,decode。
  • build_transformer_model:建立bert模型,建议看源码,可以加载多种权重和模型结构(如unilm)。
import numpy as np
from bert4keras.models import build_transformer_model
from bert4keras.tokenizers import Tokenizer
from bert4keras.snippets import to_array

config_path = '/root/kg/bert/chinese_L-12_H-768_A-12/bert_config.json'
checkpoint_path = '/root/kg/bert/chinese_L-12_H-768_A-12/bert_model.ckpt'
dict_path = '/root/kg/bert/chinese_L-12_H-768_A-12/vocab.txt'

tokenizer = Tokenizer(dict_path, do_lower_case=True)
model = build_transformer_model(
    config_path=config_path, checkpoint_path=checkpoint_path, with_mlm=True
)

token_ids, segment_ids = tokenizer.encode(u'科学技术是第一生产力')

token_ids[3] = token_ids[4] = tokenizer._token_mask_id
token_ids, segment_ids = to_array([token_ids], [segment_ids])

probas = model.predict([token_ids, segment_ids])[0]
print(tokenizer.decode(probas[3:5].argmax(axis=1)))

  • 句子1和句子2拼接在一起输入bert。
  • bert模型的pooler输出经dropout和mlp投影到2维空间,做分类问题。
  • 最终整个模型是一个标准的keras model。
class data_generator(DataGenerator):
    """数据生成器
"""
    def __iter__(self, random=False):
        batch_token_ids, batch_segment_ids, batch_labels = [], [], []
        for is_end, (text1, text2, label) in self.sample(random):
            token_ids, segment_ids = tokenizer.encode(
                text1, text2, maxlen=maxlen
            )
            batch_token_ids.append(token_ids)
            batch_segment_ids.append(segment_ids)
            batch_labels.append([label])
            if len(batch_token_ids) == self.batch_size or is_end:
                batch_token_ids = sequence_padding(batch_token_ids)
                batch_segment_ids = sequence_padding(batch_segment_ids)
                batch_labels = sequence_padding(batch_labels)
                yield [batch_token_ids, batch_segment_ids], batch_labels
                batch_token_ids, batch_segment_ids, batch_labels = [], [], []

bert = build_transformer_model(
    config_path=config_path,
    checkpoint_path=checkpoint_path,
    with_pool=True,
    return_keras_model=False,
)

output = Dropout(rate=0.1)(bert.model.output)
output = Dense(
    units=2, activation='softmax', kernel_initializer=bert.initializer
)(output)

model = keras.models.Model(bert.model.input, output)
model = build_transformer_model(
    config_path,
    checkpoint_path,
    application='unilm',
    keep_tokens=keep_tokens,
)

NLG任务的loss是交叉熵,示例中的实现很美观:

  • CrossEntropy类继承Loss类,重写compute_loss。
  • 将参与计算loss的变量过一遍CrossEntropy,这个过程中loss会被计算,具体阅读Loss类源码。
  • 最终整个模型是一个标准的keras model。
class CrossEntropy(Loss):
    """交叉熵作为loss,并mask掉输入部分
"""
    def compute_loss(self, inputs, mask=None):
        y_true, y_mask, y_pred = inputs
        y_true = y_true[:, 1:]
        y_mask = y_mask[:, 1:]
        y_pred = y_pred[:, :-1]
        loss = K.sparse_categorical_crossentropy(y_true, y_pred)
        loss = K.sum(loss * y_mask) / K.sum(y_mask)
        return loss

model = build_transformer_model(
    config_path,
    checkpoint_path,
    application='unilm',
    keep_tokens=keep_tokens,
)

output = CrossEntropy(2)(model.inputs + model.outputs)

model = Model(model.inputs, output)
model.compile(optimizer=Adam(1e-5))
model.summary()

预测阶段自回归解码,继承AutoRegressiveDecoder类可以很容易实现beam_search。

项目地址:SimBert
融合了unilm和对比学习,data generator和loss类的设计很巧妙,值得仔细阅读,建议看不懂的地方打开jupyter对着一行一行print来理解。

bert4keras项目的优点:

  • build_transformer_model一句代码构建bert模型,一个参数即可切换为unilm结构。
  • 继承Loss类,重写compute_loss方法,很容易计算loss。
  • 深度基于keras,训练、保存和keras一致。
  • 丰富的example!苏神的前沿算法研究也会附上bert4keras实现。

Original: https://blog.csdn.net/weixin_44597588/article/details/123910248
Author: 一只用R的浣熊
Title: 简洁优美的深度学习包-bert4keras