安装tensorflow
安装Tensorflow时,需要从Anaconda仓库中下载,一般默认链接的都是国外镜像地址,下载肯定很慢啊(跨国呢!),这里我是用国内清华镜像,需要改一下链接镜像的地址。这里,我们打开刚刚安装好的Anaconda中的 Anaconda Prompt,然后输入:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
再接着输入:
conda config --set show_channel_urls yes
这两行代码用来改成连接清华镜像的
使用anaconda创建虚拟环境
conda create -n tensorflow python==3.7.7
激活虚拟环境
activate tensorflow(虚拟环境名)
让pip使用国内镜像
临时使用:
可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,这样就会从清华这边的镜像去安装pyspider库。
永久修改,一劳永逸:
Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini。内容同上。
pip install tensorflow-gpu==2.1.0
或者
pip install tensorflow
使用jupyter notebook使用tensorflow
安装 pip install jupyter notebook
使用jupyter notebook
jupyter notebook