Tensorflow

下载anaconda 安装

设置国内镜像

临时使用
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

注意,simple 不能少, 是 https 而不是 http

设为默认

升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U

配置环境变量

  anaconda3/Scripts

  anaconda3/Library/bin

  anaconda3/library/mingw-64/bin

  linux:export PATH=$PATH:/home/software/anaconda3/bin

此时配置完成 操作时主要是用 scripts下的conda.exe

注意:执行命令例如: conda list

​ (4.7版本以上)若未配置path,直接找到conda 命令执行时可能会报错,

​ 需要先进入base虚拟环境 再进行conda操作 (进入condabin文件夹 conda.bat activate 进入base虚拟环境)

常用命令

  • conda info --envs 查看所有的虚拟环境

  • 创建tensorflow虚拟环境

    • conda create -n tensorflow(只是个名字) python=3.7.3(根据ananconda的版本决定)
  • conda activate tensorflow 进入tensorflow 虚拟环境

  • 安装tensorflow pip install tensorflow-gpu==版本号

  • conda deactivate 退出虚拟环境

  • pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow # for Python 3.*
    pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow-gpu # for Python 3.* and GPU

Jupyter使用

jupyter notebook  --generate-config # 生成配置文件
cNotebookApp.notebook_dir="xxx" # 修改默认路径

注意

tensorflow版本与python,cuda对应关系

版本1.1---》1.15 cuda 9及以下

版本2.0-》.... cuda 10

conda create -n py3 python=3 # 创建一个python3的环境,名为py3
source activate py3 # 激活py3环境
conda install ipykernel # 安装ipykernel模块
python -m ipykernel install --user --name=py3 # 进行配置
jupyter notebook # 启动jupyter notebook then can choose python environment

国内镜像

可能失效

阿里云
http://mirrors.aliyun.com/pypi/simple/

中国科技大学
https://pypi.mirrors.ustc.edu.cn/simple/

豆瓣(douban)
http://pypi.douban.com/simple/

清华大学
https://pypi.tuna.tsinghua.edu.cn/simple/

中国科学技术大学
http://pypi.mirrors.ustc.edu.cn/simple/

原文地址:https://www.cnblogs.com/Dean0731/p/11560371.html