Windows下安装Anaconda5.3.1+Python3.8+TensorFlow2.13.0-CPU版本总结

简介: Windows下安装Anaconda5.3.1+Python3.8+TensorFlow2.13.0-CPU版本总结

【1】Anaconda

清华的开源软件镜像站:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/下载,这里选择的是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


也可以选择从官网下载最新版本,但是可能比较慢:https://www.anaconda.com/download/

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

链接:https://pan.baidu.com/s/1IIyl5qVjCcUNrKzN8bZVvg?pwd=yyds 
提取码:yyds 

【2】TensorFlow2.13.0CPU版本

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


① 切换源

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

conda config --add channels  http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64
conda config --add channels  http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64
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 tensorflow
Name: tensorflow
Version: 2.13.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
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
tf.compat.v1.disable_eager_execution() 
hello = tf.constant('hello,tensorflow')
sess= tf.compat.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.11
  latest version: 23.10.0
Please 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
目录
相关文章
|
2天前
|
存储 数据库 时序数据库
InfluxDB的安装与Python调用
InfluxDB是一个高性能的时序数据库(Time-Series Database, TSDB),用于存储和分析时间序列数据的开源数据库,它非常适合于处理大量的时间戳数据,如金融市场数据、IoT 设备数据、监控数据等,尤其适合处理大量的时序数据和高频数据。 主要特性有: • 内置HTTP接口,使用方便 • 数据可以打标记,查询可以很灵活 • 类SQL的查询语句 • 安装管理很简单,并且读写数据很高效 • 能够实时查询,数据在写入时被索引后就能够被立即查出
InfluxDB的安装与Python调用
|
4天前
|
Python
Mac安装Python3.12开发环境
Mac安装Python3.12开发环境
17 2
|
5天前
|
Linux Python
Linux 升级安装 Python 3
Linux 升级安装 Python 3
12 2
|
5天前
|
前端开发 计算机视觉
Building wheel for opencv-python (pyproject.toml) ,安装命令增加 --verbose 参数
Building wheel for opencv-python (pyproject.toml) ,安装命令增加 --verbose 参数
16 2
|
4天前
|
Linux 网络安全 Python
Linux离线安装Python时ssh和hashlib死活安装不上的解决方案
本文提供了Linux环境下离线安装Python时遇到的"ImportError: No module named _ssl"和"ERROR:root:code for hash md5|sha1|sha224|sha256|sha384|sha512 was not found"两个问题的解决方案,通过设置OpenSSL环境变量和编辑Python源码配置文件来解决。
9 1
|
7天前
|
IDE Linux 开发工具
如何安装Python环境?
【8月更文挑战第13天】如何安装Python环境?
18 3
|
6天前
|
Python
安装notepad++ 安装Python Python环境变量的数值。怎样在notepad++上运行Python的代码
这篇文章提供了在notepad++上安装和配置Python环境的详细步骤,包括安装Python、配置环境变量、在notepad++中设置Python语言和快捷编译方式,以及解决可能遇到的一些问题。
安装notepad++ 安装Python Python环境变量的数值。怎样在notepad++上运行Python的代码
|
11天前
|
开发工具 Python Windows
【Python专栏】搭建Pyhthon运行环境及开发环境 | 安装Python | 安装PyCharm
【Python专栏】搭建Pyhthon运行环境及开发环境 | 安装Python | 安装PyCharm
41 4
|
11天前
|
并行计算 TensorFlow 算法框架/工具
Windows11+CUDA12.0+RTX4090如何配置安装Tensorflow2-GPU环境?
本文介绍了如何在Windows 11操作系统上,配合CUDA 12.0和RTX4090显卡,通过创建conda环境、安装特定版本的CUDA、cuDNN和TensorFlow 2.10来配置TensorFlow GPU环境,并提供了解决可能遇到的cudnn库文件找不到错误的具体步骤。
48 3