• python 安装 tensorflowjs


    python 安装 tensorflowjs

    最近在学习 tfjs 中的模型转换, 需要在 python 中安装 tensorflowjs.

    操作系统: win10x64
    操作步骤:

    • 下载 miniconda 并安装, 因为 x64 上一般都能运行 x32, 为保持兼容性我下载了 Miniconda3-latest-Windows-x86.exe
    • 运行 conda create -n tfjs python=3.6.8 安装 python 环境
    • 运行 conda activate tfjs 激活环境
    • 运行 pip install tensorflowjs 来安装 tensorflowjs

    To fix this you could try to:

    1. loosen the range of package versions you’ve specified
    2. remove package versions to allow pip attempt to solve the dependency conflict

    各种谷歌、必应、百度、stackoverflow、issues 得到大概以下方案:

    反复清除环境重新安装

    是不是由于安装过程中我按 ctrl+c 导致依赖安装中断, 环境坏了? 那么我卸载环境重新初始化环境.

    • conda remove -n tfjs
    • conda activate tfjs
    • 未解决!

    更换镜像

    是不是像 npm 一样依赖安装失败, 可以尝试换镜像解决?

    • 使用命令方式配置 pip 镜像, 未解决!
    • 更换配置文件中的镜像, 未解决!
    • 更换各种镜像源重试, 未解决!

    重新安装 conda

    我的 conda 是 mini 版本的(56M), 有很多依赖要重新安装, 如果我使用完整版的(418M), 是不是那些依赖就已经自带了?

    • 卸载 miniconda, 重新下载安装完整版 conda Anaconda3-2021.05-Windows-x86.exe, 删除环境重试, 未解决!

    放宽版本限制

    网上说去除 requirements.txt 中的版本, 但我也没有 requirements.txt 文件啊! 我也没有指定 tensorflowjs 的版本啊.

    未解决!

    升级 pip

    使用 pip install --upgrade pip 升级过程中报错拒绝访问, 然后再执行 pip 的时候报错 Script file '******' is not present.

    解决方法:
    运行 conda install -f pip 使用 conda 强制安装 pip, 这才让 pip 重新可以使用.
    然后使用 pip install --user --upgrade pip 才能升级 pip 成功.

    然后重试安装 tensorflowjs, 未解决!

    与教程版本一致

    是不是由于 pip install tensorflowjs 过程中安装了有依赖兼容问题的版本, 导致问题, 于是重新逐步看视频, 保持版本一致. 虽然教程没有指定版本安装, 但可以在控制台在安装日志中发现猫腻:

    absl-py-x.x.x astunparse-x.x.x cached-property-x.x.x cachetools-x.x.x charset-normalizer-x.x.x clang-x.x.x google-auth-x.x.x google-auth-oauthlib-x.x.x google-pasta-x.x.x grpcio-x.x.x h5py-x.x.x idna-x.x.x keras-x.x.x keras-preprocessing-x.x.x markdown-x.x.x numpy-x.x.x oauthlib-x.x.x opt-einsum-x.x.x protobuf-x.x.x pyasn1-x.x.x pyasn1-modules-x.x.x requests-x.x.x requests-oauthlib-x.x.x rsa-x.x.x six-x.x.x tensorboard-x.x.x tensorboard-data-server-x.x.x tensorboard-plugin-wit-x.x.x tensorflow-x.x.x tensorflow-estimator-x.x.x tensorflow-hub-x.x.x tensorflowjs-x.x.x termcolor-x.x.x typing-extensions-x.x.x.x urllib3-x.x.x werkzeug-x.x.x wrapt-x.x.x zipp-x.x.x

    在其中发现 tensorflowjs-1.3.1.1.

    • 然后尝试 pip install tensorflowjs=1.3.1.1, 报错

      ERROR: Invalid requirement: ‘tensorflowjs=1.3.1.1’ Hint: = is not a valid operator. Did you mean == ?

    • 再尝试 pip install tensorflowjs=1.3.1.1, 正在安装, 但还是报错

      ERROR: Could not find a version that satisfies the requirement tensorflow==1.15.0 (from tensorflowjs) (from versions: none)
      ERROR: No matching distribution found for tensorflow==1.15.

    看起来是 tensorflow==1.15 这个版本的依赖没有找到, 奇怪, 这个版本号又不是我指定的, 是 tensorflowjs 自己依赖的, 怎么会找不到? 难道是镜像源没有同步到这个版本?
    然后在网上找各种镜像源进行替换重试:

    有的报错没有 tensorflowjs==1.3.1.1, 有的报错没有 tensorflow==1.15. 看起来镜像确实会引发问题. 但是能找到的镜像挨个都试了, 1.15 没找到的问题还是未解决!

    搜索 tensorflow==1.15 找不到的问题

    然后有注意到 https://www.cnblogs.com/wang1yi1xian1/p/12166443.html 这篇文章说:

    检查 python 版本。好像目前 tensorflow 只支持 python3.5.x 64bit~3.6.x 64bit 版本。(重点:python 版本必须是 64bit 的。32bit 安装 tensorflow 还是会报错)
    确认 python 版本是:python3.6.x-64bit,使用管理员权限直接在终端运行:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow ,就可以安装成功。
    我用的是:python3.6.4-64bit 版本。

    其中只支持 python3.x 倒是知道, 我使用的就是 python3.6.8, 但是只支持 x64 这个 github 上也没提, 教程上也没提, 然后我也想当然的像一般软件一样认为 x64 的系统安装 x32 的 conda 软件也没问题的.

    于是到 conda 中运行 python 查看了一下输出:

    (tfjs) D:git2	f-fe>python
    Python 3.6.8 |Anaconda, Inc.| (default, Feb 21 2019, 18:28:22) [MSC v.1916 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    

    注意到其中的 win32 字样应该是 x32 版本的 python. 好家伙, 我安装的是 conda x32, 所以 conda 安装的依赖都是 x32 的?

    安装符合系统位数的 conda

    于是下载 Miniconda3-latest-Windows-x86_64.exe 重试, 没有更新 pip 直接运行 pip install tensorflowjs , 安装过程中没有遇到任何错误, 使用 tensorflowjs_converter -h 测试.

    Successfully installed absl-py-0.14.1 astunparse-1.6.3 cached-property-1.5.2 cachetools-4.2.4 charset-normalizer-2.0.7 clang-5.0 dataclasses-0.8 flatbuffers-1.12 gast-0.4.0 google-auth-2.3.0 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.41.0 h5py-3.1.0 idna-3.3 importlib-metadata-4.8.1 keras-2.6.0 keras-preprocessing-1.1.2 markdown-3.3.4 numpy-1.19.5 oauthlib-3.1.1 opt-einsum-3.3.0 protobuf-3.18.1 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.26.0 requests-oauthlib-1.3.0 rsa-4.7.2 six-1.15.0 tensorboard-2.7.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.0 tensorflow-2.6.0 tensorflow-estimator-2.6.0 tensorflow-hub-0.12.0 tensorflowjs-3.9.0 termcolor-1.1.0 typing-extensions-3.7.4.3 urllib3-1.26.7 werkzeug-2.0.2 wrapt-1.12.1 zipp-3.6.0
    
    (tfjs) D:git2	f-fe>tensorflowjs_converter -h
    2021-10-19 10:53:40.097944: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
    2021-10-19 10:53:40.098591: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
    usage: TensorFlow.js model converters. [-h]
    
  • 相关阅读:
    生物创新科技素养大赛小车代码
    对拍程序
    Link-Cut-Tree学习笔记
    可平面性判定,任意平面图判定(代码实现)
    强联通缩点拓扑排序去重边小技巧
    20200405~06题解
    数论总结
    20200328题解
    Dp优化总结
    20200314题解
  • 原文地址:https://www.cnblogs.com/daysme/p/15423908.html
Copyright © 2020-2023  润新知