$conda config --set show_channel_urls yes
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
$conda upgrade --all
$conda create -n tf python=3.6
# Windows
$activate tf
# Linux & macOS
$source activate tf
# Windows
$deactivate
# Linux & macOS
$source deactivate
$conda env list
# env_name为待删除环境名
$conda env remove -n env_name
# 以TensorFlow为例
# 最好也将pip源改为TUNA源
升级 pip 到最新的版本 (必须升级) 后进行配置:
$ pip install pip -U
$ pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# pip与conda均可安装 CPU版本最好用conda
$pip install tensorflow
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello).decode())
输出为: Hello, TensorFlow!
$pip install jupyter
windows下的配置文件
{
"language": "python",
"display_name": "tensorflow",
"argv": [
"C:\\ProgramData\\Anaconda3\\envs\\tf\\python.exe",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
]
}
ubuntu下的配置文件:
{
"argv": [
"/home/你的用户名/anaconda3/envs/tf/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "TensorFlow",
"language": "python"
}
macOS下的配置文件:
{
"argv": [
"/Users/你的用户名/anaconda3/envs/tf/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "TensorFlow",
"language": "python"
}
$conda install -n tf ipykernel
$conda install nb_conda
Error
An error occurred while retrieving installed packages.
EnvironmentLocationNotFound: Not a conda environment: C:\ProgramData\Anaconda3\envs\Anaconda3
ipykernel
,选中复选框,点击search框右边的箭头,将其安装进虚拟环境中。安装完成后,重启浏览器,即可在右上角新建notebook中看到待使用的配置好的虚拟环境修改 ~/.jupyter/custom/custom.css 的内容,如果没有此文件,新建即可。
.CodeMirror pre {font-family: consolas; font-size: 12pt;}
* {font-family: consolas;}
div.output_area pre {font-family: consolas; font-size: 12pt;}
div.input_prompt {font-family: consolas; font-size: 12pt;}
div.out_prompt_overlay {font-family: consolas; font-size: 12pt;}
div.prompt {font-family: consolas; font-size: 12pt;}
span.cm-comment {font-family: consolas ; font-style:normal ; color:#FFAE3C ;}