TensorFlow基于anaconda3快速构建

基于python构建太累

Installing Packages - Python Packaging User Guide

使用 pip 安装 TensorFlow

有兴趣自己学,我放弃了


下面基于anaconda

1、下载

Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

自己找一个,我用的最底下的,600m大小,安装完成要2.3个G

2、安装

坑1:要选64bit的,要不然一弄一上午,一弄不吱声

坑2:尽可能一定要用管理员权限安装,一直往下点

ps:遇到vscode可以直接skip

3、软调

conda info -e 看环境

conda env remove --name your_env_name 删除环境

conda create -n TF2.1 python=3.7

坑3:可以python3.6 3.7 3.8 各个都说有道理,你自己试验,能装上,但是一定要64位。。。

等收集完环境自己确认,点y安装

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    ca-certificates-2024.3.11  |       haa95532_0         168 KB
    sqlite-3.45.3              |       h2bbff1b_0         1.4 MB
    vs2015_runtime-14.27.29016 |       h5e58377_2         2.2 MB
    certifi-2022.12.7          |   py37haa95532_0         152 KB
    pip-22.3.1                 |   py37haa95532_0         2.7 MB
    openssl-1.1.1w             |       h2bbff1b_0         5.8 MB
    setuptools-65.6.3          |   py37haa95532_0         1.4 MB
    vc-14.2                    |       h21ff451_1           8 KB
    wincertstore-0.2           |   py37haa95532_2          15 KB
    python-3.7.16              |       h6244533_0        17.9 MB
    wheel-0.38.4               |   py37haa95532_0          76 KB
    ------------------------------------------------------------
                                           Total:        31.8 MB

The following NEW packages will be INSTALLED:

    ca-certificates: 2024.3.11-haa95532_0
    certifi:         2022.12.7-py37haa95532_0
    openssl:         1.1.1w-h2bbff1b_0
    pip:             22.3.1-py37haa95532_0
    python:          3.7.16-h6244533_0
    setuptools:      65.6.3-py37haa95532_0
    sqlite:          3.45.3-h2bbff1b_0
    vc:              14.2-h21ff451_1
    vs2015_runtime:  14.27.29016-h5e58377_2
    wheel:           0.38.4-py37haa95532_0
    wincertstore:    0.2-py37haa95532_2

Proceed ([y]/n)? y

坑4:完成后各种教程有争议

conda activate name 或者activate name 开启,我的是后者,自行判断,

坑5:预配置钱要先配置源,要不还是不吱声

C:\Users\Administrator>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
Warning: 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/' already in 'channels' list, moving to the top

C:\Users\Administrator>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
Warning: 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/' already in 'channels' list, moving to the top

C:\Users\Administrator>conda config --show-sources
==> C:\Users\Administrator\.condarc <==
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
  - defaults

坑6:GPU预置,可跳过

conda install cudatoolkit=10.1

conda install cudnn=7.6

4、安装

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

妥妥赢家

C:\Users\Administrator>      pip install tensorflow==2.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting tensorflow==2.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/34/d5/ce8c17971067c0184c9045112b755be5461d5ce5253ef65a367e1298d7c5/tensorflow-2.1.0-cp37-cp37m-win_amd64.whl (355.8 MB)
     ---------------------------------------- 355.8/355.8 MB 5.4 MB/s eta 0:00:00
Collecting protobuf>=3.8.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/61/70/ee9585603255156d88f07528a6094733e37f8e3f72711b8583fcbb77d5ec/protobuf-4.24.4-cp37-cp37m-win_amd64.whl (430 kB)
     ---------------------------------------- 430.0/430.0 kB 13.5 MB/s eta 0:00:00
Requirement already satisfied: wheel>=0.26 in d:\programdata\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.38.4)
Collecting tensorflow-estimator<2.2.0,>=2.1.0rc0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/18/90/b77c328a1304437ab1310b463e533fa7689f4bfc41549593056d812fab8e/tensorflow_estimator-2.1.0-py2.py3-none-any.whl (448 kB)
     ---------------------------------------- 449.0/449.0 kB 13.7 MB/s eta 0:00:00
Collecting scipy==1.4.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/61/51/046cbc61c7607e5ecead6ff1a9453fba5e7e47a5ea8d608cc7036586a5ef/scipy-1.4.1-cp37-cp37m-win_amd64.whl (30.9 MB)
     ---------------------------------------- 30.9/30.9 MB 16.8 MB/s eta 0:00:00
Collecting keras-applications>=1.0.8
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/71/e3/19762fdfc62877ae9102edf6342d71b28fbfd9dea3d2f96a882ce099b03f/Keras_Applications-1.0.8-py3-none-any.whl (50 kB)
     ---------------------------------------- 50.7/50.7 kB ? eta 0:00:00
Collecting opt-einsum>=2.3.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bc/19/404708a7e54ad2798907210462fd950c3442ea51acc8790f3da48d2bee8b/opt_einsum-3.3.0-py3-none-any.whl (65 kB)
     ---------------------------------------- 65.5/65.5 kB 3.7 MB/s eta 0:00:00
Collecting google-pasta>=0.1.6
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a3/de/c648ef6835192e6e2cc03f40b19eeda4382c49b5bafb43d88b931c4c74ac/google_pasta-0.2.0-py3-none-any.whl (57 kB)
     ---------------------------------------- 57.5/57.5 kB 3.0 MB/s eta 0:00:00
Collecting absl-py>=0.7.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a2/ad/e0d3c824784ff121c03cc031f944bc7e139a8f1870ffd2845cc2dd76f6c4/absl_py-2.1.0-py3-none-any.whl (133 kB)
     ---------------------------------------- 133.7/133.7 kB 8.2 MB/s eta 0:00:00
Collecting gast==0.2.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4e/35/11749bf99b2d4e3cceb4d55ca22590b0d7c2c62b9de38ac4a4a7f4687421/gast-0.2.2.tar.gz (10 kB)
  Preparing metadata (setup.py) ... done
Collecting keras-preprocessing>=1.1.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/79/4c/7c3275a01e12ef9368a892926ab932b33bb13d55794881e3573482b378a7/Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)
     ---------------------------------------- 42.6/42.6 kB ? eta 0:00:00
Collecting six>=1.12.0
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting termcolor>=1.1.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/67/e1/434566ffce04448192369c1a282931cf4ae593e91907558eaecd2e9f2801/termcolor-2.3.0-py3-none-any.whl (6.9 kB)
Collecting wrapt>=1.11.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/66/a5/50e6a2bd4cbf6671012771ec35085807a375da5e61540bc5f62de62ba955/wrapt-1.16.0-cp37-cp37m-win_amd64.whl (37 kB)
Collecting tensorboard<2.2.0,>=2.1.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d9/41/bbf49b61370e4f4d245d4c6051dfb6db80cec672605c91b1652ac8cc3d38/tensorboard-2.1.1-py3-none-any.whl (3.8 MB)
     ---------------------------------------- 3.8/3.8 MB 27.2 MB/s eta 0:00:00
Collecting grpcio>=1.8.6
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cb/a8/9344f2d3499b59ad8acbb190d97aba0f292f9165c4afc49341d0decdc569/grpcio-1.62.2-cp37-cp37m-win_amd64.whl (4.5 MB)
     ---------------------------------------- 4.5/4.5 MB 28.7 MB/s eta 0:00:00
Collecting numpy<2.0,>=1.16.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/97/9f/da37cc4a188a1d5d203d65ab28d6504e17594b5342e0c1dc5610ee6f4535/numpy-1.21.6-cp37-cp37m-win_amd64.whl (14.0 MB)
     ---------------------------------------- 14.0/14.0 MB 40.9 MB/s eta 0:00:00
Collecting astor>=0.6.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c3/88/97eef84f48fa04fbd6750e62dcceafba6c63c81b7ac1420856c8dcc0a3f9/astor-0.8.1-py2.py3-none-any.whl (27 kB)
Collecting h5py
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/44/c6/ebb183fcd341681fe41d86b10790335c27372dd279189ab514c75acdbfb2/h5py-3.8.0-cp37-cp37m-win_amd64.whl (2.6 MB)
     ---------------------------------------- 2.6/2.6 MB 55.7 MB/s eta 0:00:00
Collecting requests<3,>=2.21.0
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/70/8e/0e2d847013cb52cd35b38c009bb167a1a26b2ce6cd6965bf26b47bc0bf44/requests-2.31.0-py3-none-any.whl (62 kB)
Collecting markdown>=2.6.8
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1a/b5/228c1cdcfe138f1a8e01ab1b54284c8b83735476cb22b6ba251656ed13ad/Markdown-3.4.4-py3-none-any.whl (94 kB)
     ---------------------------------------- 94.2/94.2 kB 5.6 MB/s eta 0:00:00
Collecting werkzeug>=0.11.15
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f6/f8/9da63c1617ae2a1dec2fbf6412f3a0cfe9d4ce029eccbda6e1e4258ca45f/Werkzeug-2.2.3-py3-none-any.whl (233 kB)
     ---------------------------------------- 233.6/233.6 kB 14.0 MB/s eta 0:00:00
Requirement already satisfied: setuptools>=41.0.0 in d:\programdata\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (65.6.3)
Collecting google-auth<2,>=1.6.3
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fb/7a/1b3eb54caee1b8c73c2c3645f78a382eca4805a301a30c64a078e736e446/google_auth-1.35.0-py2.py3-none-any.whl (152 kB)
     ---------------------------------------- 152.9/152.9 kB ? eta 0:00:00
Collecting google-auth-oauthlib<0.5,>=0.4.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b1/0e/0636cc1448a7abc444fb1b3a63655e294e0d2d49092dc3de05241be6d43c/google_auth_oauthlib-0.4.6-py2.py3-none-any.whl (18 kB)
Collecting pyasn1-modules>=0.2.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cd/8e/bea464350e1b8c6ed0da3a312659cb648804a08af6cacc6435867f74f8bd/pyasn1_modules-0.3.0-py2.py3-none-any.whl (181 kB)
     ---------------------------------------- 181.3/181.3 kB 10.7 MB/s eta 0:00:00
Collecting cachetools<5.0,>=2.0.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ea/c1/4740af52db75e6dbdd57fc7e9478439815bbac549c1c05881be27d19a17d/cachetools-4.2.4-py3-none-any.whl (10 kB)
Collecting rsa<5,>=3.1.4
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/49/97/fa78e3d2f65c02c8e1268b9aba606569fe97f6c8f7c2d74394553347c145/rsa-4.9-py3-none-any.whl (34 kB)
Collecting requests-oauthlib>=0.7.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/3b/5d/63d4ae3b9daea098d5d6f5da83984853c1bbacd5dc826764b249fe119d24/requests_oauthlib-2.0.0-py2.py3-none-any.whl (24 kB)
Collecting importlib-metadata>=4.4
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ff/94/64287b38c7de4c90683630338cf28f129decbba0a44f0c6db35a873c73c4/importlib_metadata-6.7.0-py3-none-any.whl (22 kB)
Collecting charset-normalizer<4,>=2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/96/fc/0cae31c0f150cd1205a2a208079de865f69a8fd052a98856c40c99e36b3c/charset_normalizer-3.3.2-cp37-cp37m-win_amd64.whl (98 kB)
     ---------------------------------------- 98.1/98.1 kB 5.9 MB/s eta 0:00:00
Requirement already satisfied: certifi>=2017.4.17 in d:\programdata\anaconda3\envs\tf2.1\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (2022.12.7)
Collecting urllib3<3,>=1.21.1
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d2/b2/b157855192a68541a91ba7b2bbcb91f1b4faa51f8bae38d8005c034be524/urllib3-2.0.7-py3-none-any.whl (124 kB)
Collecting idna<4,>=2.5
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e5/3e/741d8c82801c347547f8a2a06aa57dbb1992be9e948df2ea0eda2c8b79e8/idna-3.7-py3-none-any.whl (66 kB)
Collecting MarkupSafe>=2.1.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6c/4c/3577a52eea1880538c435176bc85e5b3379b7ab442327ccd82118550758f/MarkupSafe-2.1.5-cp37-cp37m-win_amd64.whl (17 kB)
Collecting typing-extensions>=3.6.4
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ec/6b/63cc3df74987c36fe26157ee12e09e8f9db4de771e0f3404263117e75b95/typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Collecting zipp>=0.5
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5b/fa/c9e82bbe1af6266adf08afb563905eb87cab83fde00a0a08963510621047/zipp-3.15.0-py3-none-any.whl (6.8 kB)
Collecting pyasn1<0.6.0,>=0.4.6
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d1/75/4686d2872bf2fc0b37917cbc8bbf0dd3a5cdb0990799be1b9cbf1e1eb733/pyasn1-0.5.1-py2.py3-none-any.whl (84 kB)
     ---------------------------------------- 84.9/84.9 kB 5.0 MB/s eta 0:00:00
Collecting oauthlib>=3.0.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7e/80/cab10959dc1faead58dc8384a781dfbf93cb4d33d50988f7a69f1b7c9bbe/oauthlib-3.2.2-py3-none-any.whl (151 kB)
     ---------------------------------------- 151.7/151.7 kB 8.8 MB/s eta 0:00:00
Building wheels for collected packages: gast
  Building wheel for gast (setup.py) ... done
  Created wheel for gast: filename=gast-0.2.2-py3-none-any.whl size=7549 sha256=a076a0856a88175f0b225e64c76ae34eccca1c902dd4b35a412c90d00c0f6955
  Stored in directory: c:\users\administrator\appdata\local\pip\cache\wheels\cc\0e\83\9f24c5972affa5a98636935d34edb987be537aba9f10e43d4b
Successfully built gast
Installing collected packages: tensorflow-estimator, zipp, wrapt, urllib3, typing-extensions, termcolor, six, pyasn1, protobuf, oauthlib, numpy, MarkupSafe, idna, grpcio, gast, charset-normalizer, cachetools, astor, absl-py, werkzeug, scipy, rsa, requests, pyasn1-modules, opt-einsum, keras-preprocessing, importlib-metadata, h5py, google-pasta, requests-oauthlib, markdown, keras-applications, google-auth, google-auth-oauthlib, tensorboard, tensorflow
Successfully installed MarkupSafe-2.1.5 absl-py-2.1.0 astor-0.8.1 cachetools-4.2.4 charset-normalizer-3.3.2 gast-0.2.2 google-auth-1.35.0 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.62.2 h5py-3.8.0 idna-3.7 importlib-metadata-6.7.0 keras-applications-1.0.8 keras-preprocessing-1.1.2 markdown-3.4.4 numpy-1.21.6 oauthlib-3.2.2 opt-einsum-3.3.0 protobuf-4.24.4 pyasn1-0.5.1 pyasn1-modules-0.3.0 requests-2.31.0 requests-oauthlib-2.0.0 rsa-4.9 scipy-1.4.1 six-1.16.0 tensorboard-2.1.1 tensorflow-2.1.0 tensorflow-estimator-2.1.0 termcolor-2.3.0 typing-extensions-4.7.1 urllib3-2.0.7 werkzeug-2.2.3 wrapt-1.16.0 zipp-3.15.0

5、验证

python

import tensorflow as tf

坑7:编译器提示的信息下载3.19.0,属于二选一

pip install protobuf==3.19.0

pip install protoc==3.19.0

继续验证命令

tf.version

6、pycharm 预置环境

选择 解释器的conda环境

坑8:Anaconda安装目录下,找到envs文件夹,选择TF2.1文件夹,选中里面的python.exe

坑9:

如果终端不想输出Tensorflow的标红日志,您可以在import tensorflow前面输入如下命令:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
相关推荐
古希腊掌管学习的神1 小时前
[机器学习]XGBoost(3)——确定树的结构
人工智能·机器学习
ZHOU_WUYI1 小时前
4.metagpt中的软件公司智能体 (ProjectManager 角色)
人工智能·metagpt
靴子学长2 小时前
基于字节大模型的论文翻译(含免费源码)
人工智能·深度学习·nlp
梧桐树04293 小时前
python常用内建模块:collections
python
AI_NEW_COME3 小时前
知识库管理系统可扩展性深度测评
人工智能
Dream_Snowar3 小时前
速通Python 第三节
开发语言·python
海棠AI实验室3 小时前
AI的进阶之路:从机器学习到深度学习的演变(一)
人工智能·深度学习·机器学习
hunteritself3 小时前
AI Weekly『12月16-22日』:OpenAI公布o3,谷歌发布首个推理模型,GitHub Copilot免费版上线!
人工智能·gpt·chatgpt·github·openai·copilot
IT古董4 小时前
【机器学习】机器学习的基本分类-强化学习-策略梯度(Policy Gradient,PG)
人工智能·机器学习·分类
centurysee4 小时前
【最佳实践】Anthropic:Agentic系统实践案例
人工智能