Windows下安装Anaconda5.3.1+Python3.8+TensorFlow2.13.0

编程入门 行业动态 更新时间:2024-10-11 15:13:49

<a href=https://www.elefans.com/category/jswz/34/1771365.html style=Windows下安装Anaconda5.3.1+Python3.8+TensorFlow2.13.0"/>

Windows下安装Anaconda5.3.1+Python3.8+TensorFlow2.13.0

Python3.8安装可以参考博文 进行安装即可。

【1】Anaconda

清华的开源软件镜像站:,这里选择的是5.3.1版本。

然后正常安装就可以,安装路径这里选择的是E:\softinstall\Anaconda

安装后在Windows的开始菜单找到Anaconda Prompt并打开可以检测版本与环境信息。

base) C:\Users\Janus>conda --version
conda 4.5.11(base) C:\Users\Janus>conda info --envs
# conda environments:
#
base                  *  E:\softinstall\Anaconda

也可以选择从官网下载最新版本,但是可能比较慢:/

这个官网下载是真的慢,花了蛮久下载了Anaconda3-2023.09-0-Windows-x86_64.exe,下面是百度云链接:

链接:=yyds 
提取码:yyds 

【2】TensorFlow2.13.0CPU版本

TensorFlow 2.13.0版本需要Python版本: Requires: Python >=3.8

① 切换源

因为国外的网站下载速度很慢,所以先把anaconda的源换成清华镜像:

conda config --add channels  
conda config --add channels  
conda config --set show_channel_urls yes

注意哦,这里是http且最后加了win-64。

当然也可以直接修改anaconda的配置文件.condarc,改文件在家目录下我这里是C:\Users\Janus

② 创建并激活环境

命令如下所示,当询问是否执行时,输入y(yes) 。

#创建环境
conda create --name python38 python=3.8#激活环境
conda activate python38#退出环境
conda deactivate

③ 在环境“python38”下安装TensorFlow

pip install tensorflow#或者直接指定版本
pip install tensorflow==2.13.0

④ 查看TensorFlow版本

① 使用TensorFlow自带的版本查看功能

(python38) C:\Users\Janus>python
Python 3.8.18 (default, Sep 11 2023, 13:39:12) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> print(tf.version.VERSION)
2.13.0
>>> print(tf.__version__)
2.13.0
>>> exit()

这里表示安装的TensorFlow是2.13.0。

② 检查TensorFlow使用的Python版本

可以使用如下代码来确定正在使用哪个版本的Python:

import tensorflow as tf
print(tf.version.PYTHON_VERSION)

③ 使用命令行查看TensorFlow版本

可以使用pip show命令查看当前安装的TensorFlow版本:

(python38) E:\softinstall\Jupyter>pip show tensorflowName: tensorflow
Version: 2.13.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: /
Author: Google Inc.
Author-email: packages@tensorflow
License: Apache 2.0
Location: e:\softinstall\anaconda\envs\python38\lib\site-packages
Requires: tensorflow-intel
Required-by:

⑤ 测试Tensorflow

如下代码成功打印hello,tensorflow即说明成功。

import tensorflow as tf
tfpat.v1.disable_eager_execution() 
hello = tf.constant('hello,tensorflow')
sess= tfpat.v1.Session()
print(sess.run(hello))

【3】使用jupyter notebook

① 首先激活对应的conda环境

conda activate python38

② 安装ipykernel

在Anaconda 环境下优先使用conda install XXXX来安装包,如果不可以或者有特殊需求可采用pip install

(python38) C:\Users\Janus>conda install ipykernel
Solving environment: done==> WARNING: A newer version of conda exists. <==current version: 4.5.11latest version: 23.10.0Please update conda by running$ conda update -n base -c defaults conda# All requested packages already installed.

③ 切换到编程文件保存的目录

默认在C盘,我这里是:E:\softinstall\Jupyter

(python38) C:\Users\Janus>E:(python38) E:\>cd softinstall(python38) E:\softinstall>cd Jupyter

④ 将环境写入notebook的kernel中

(python38) E:\softinstall\Jupyter>python -m ipykernel install --user --name python38 --display-name "Python (python38)"
Installed kernelspec python38 in C:\Users\Janus\AppData\Roaming\jupyter\kernels\python38

⑤ 打开jupyter

安装Anaconda后自带Jupyter Notebook。在anaconda命令行中执行 jupyter notebook 就可以。

(python38) E:\softinstall\Jupyter>jupyter notebook

浏览器页面选择Python(python38)的Kernel即可

【4】遇到的问题总结

① 执行脚本提示 No module named ‘tensorflow’

这里查看jupyter kernelspec list ,其地址指向一个包含kernel.json的文件夹,打开这个json文件,发现里面指向的python.exe仍然是python3.7。

(python38) C:\Users\Janus>jupyter kernelspec list
Available kernels:python3    E:\softinstall\Anaconda\share\jupyter\kernels\python3

重新安装Jupyter

conda install jupyter notebook

此外如果还需要什么环境比如pandas,那么在python38环境下安装即可,如canda install pandas

② No module named ‘matplotlib’

conda install  matplotlib

③ No module named ‘sklearn’

conda install scikit-learn

④ partially initialized module ‘charset_normalizer’ has no attribute ‘md__mypyc’ (most likely due to a circular import)

conda install chardet
#或者
pip install chardet

更多推荐

Windows下安装Anaconda5.3.1+Python3.8+TensorFlow2.13.0

本文发布于:2023-11-15 07:37:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596051.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!