0. 安装Nvidia驱动
D:\> nvidia-smi
D:\> nvcc -V
安装CUDA
安装cuDNN
解压CuDNN压缩包 把bin、include、lib目录中的文件复制到 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1下的对应目录中 把以下目录添加path中:
C:\ Program Files\ NVIDIA GPU Computing Toolkit\ CUDA\ v11.1
C:\ Program Files\ NVIDIA GPU Computing Toolkit\ CUDA\ v11.1\ lib\ x64
1.Anaconda3:
conda create -n 环境名 numpy python=3.6 #后面可以接其他包 =用来指明版本
conda list # 查看安装包列表
conda --version # 查看版本号
conda info -e #用于查看拥有的环境
conda remove -n 虚拟环境名称 --all #删除对应环境
conda create –n 新名 –-clone 旧名 #用于克隆,改名也蛮好的
Anaconda3安装完成之后,以管理员身份运行anaconda propmt 更新所有的库
conda update --all
若Win10安装Anacondad3之后没有pip则执行:
# 以管理员身份运行
cd C:\ProgramData\Anaconda3\Scripts
easy_install.exe pip
python -m pip install --user --upgrade pip
2. 安装
python - m pip install -- user -- upgrade pip
conda create - n ai pip python= 3.6
conda activate ai
conda deactivate
$ pip install SomePackage # 最新版本
$ pip install SomePackage== 1.0 .4 # 指定版本
$ pip install 'SomePackage>= 1.0 .4 ' # 最小版本
conda config --set auto_activate_base false
(ai)xx> pip install torch===1.3.1 torchvision===0.4.1 -f torch-1.3.1-cp36-cp36m-win_amd64.whl
# 或指定多个文件
(ai)xx>pip3 install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio===0.8.1 -f torch-1.8.1+cu111-cp39-cp39-win_amd64.whl -f torchvision-0.9.1+cu111-cp39-cp39-win_amd64.whl
import torch
import torchvision
print(torch.__version__)
print(torch.cuda.is_available()) # 返回True, 则PyTorch的GPU安装成功
pip install Pillow==6.1 # ImportError: cannot import name 'PILLOW_VERSION'
使用Pip更新Pytorch和torchvision
# 列举pip当前可以更新的所有安装包
pip list -- outdated -- format= legacy
# 更新pytorch和torchvision安装包
pip install -- upgrade pytorch torchvision
使用conda更新Pytorch和torchvision
# 建议将其添加soumith为您的Anaconda(或Miniconda)的源服务器
conda config -- add channels soumith
# 更新pytorch和torchvision安装包
conda update pytorch torchvision
pip uninstall torch
https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.0.0-cp36-cp36m-win_amd64.whl
pip install tensorflow-gpu==2.0.0 -f d:\ztools\tensorflow_gpu-2.0.0-cp36-cp36m-win_amd64.whl
pip install --user --upgrade tensorflow #升级到最新版本 (不支持GPU)
pip install --user --upgrade tensorflow-gpu #升级到最新版本 (支持GPU)
import tensorflow as tf;
print(tf.__version__) # 获取TensorFlow版本号
import tensorflow as tf;
tf.test.is_built_with_cuda() #检测cuda 返回true或者false
tf.test.is_gpu_available() # 检测gpu 返回true或者false
# 如果两个都是true 那么gpu就安装好了
# FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)])
pip install numpy==1.16.0
pip install opencv-python==4.1.2.30 # only install main modules
pip install opencv-contrib-python==4.1.2.30 # install both main and contrib modules
import cv2
print(cv2.__version__)
2.4 Win10下载安装Graphviz
注:pip install graphviz安装可以成功,但无效(即plot_model报错) 下载地址
https: / / www2. graphviz. org/ Packages/ development/ windows/ 10 / cmake/ Release/ x64/
3. 问题解决
3.1 安装Anaconda3
3.1.1 Install Microsfot VSCode failed
解决方案:在/anaconda3/pkgs/vscode_inst.py中的def haveInternet():中增加允许重定向allow_redirects=True
def haveInternet():
try:
r = requests.head(VSCODE_ENDPOINT, timeout=5, allow_redirects=True)
assert r.status_code == 200
return True
except Exception as e:
log.exception('haveInternet')
return False
4. 修改Anaconda中Jupyter Notebook默认路径
jupyter notebook --generate-config
修改jupyter_notebook_config.py
c.NotebookApp.notebook_dir = 'E:\Jupyter'
jupyter-lab --generate-config
c.ServerApp.notebook_dir = 'D:\Jupyter'
打開jupyter notebook的快捷方式,按右鍵選內容-属性。
将起始位置:后面的内容改为你的路径,如:D:\Jupyter这样的路径 将目标:%USERPROFILE%/ 改为 起始位置填写的一样的路径
5. 把Conda虚拟环境增加到jupyter notebook的kernel中
5.1 方案1
在Conda虚拟环境增加到jupyter notebook的kernel中,即在Conda虚拟环境中安装jupyter notebook
打开Anaconda Navigator, 在【Applications on】中选择自己的Conda虚拟环境名称,然后点【jupyter notebook】下方的【Install】 安装好之后,就变成【Launch】了 启动Jupyter Notebook之后,就可在 Kernel => Change kernel中选择自己的虚拟环境了,如 Python [conda env: mytensorflow]
# 安装jupyter notebook
pip install ipykernel
pip install jupyter
# 创建conda环境
# 激活环境
# 把conda env 增加到jupyter notebook kernel中
( ai) D: \> python3 - m ipykernel install -- user -- name tf -- display- name "Python3(tf)"
# 打开notebook服务器:
( ai) D: \> jupyter notebook
# 如果经常需要用jupyter notebook,那么最好在创建虚拟环境的时候便安装好ipykernel
conda create - n 环境名称 python= 3.5 ipykernel
# 查看jupyter notebook kernel
jupyter kernelspec list
# 删除jupyter notebook kernel
jupyter kernelspec remove kernelname
6. 在PyCharm中设置Conda虚拟环境
File=>Settings=>Proejct:basic=>Project Interpreter=>Add=>Conda Evironment=>Existing environment=>Interpreter 选择Conda虚拟环境下的python.exe,如:C:\Anaconda3\envs\mytensorflow\python.exe
7. TensorFlow FutureWarning
Python36\ site-packages\ tensorboard\ compat\ tensorflow_stub\ dtypes.py:541: FutureWarning: Passing ( type, 1 ) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as ( type, ( 1 ,)) / '(1,)type' . _np_qint8 = np.dtype( [ ( "qint8" , np.int8, 1 ) ] )
np.dtype( [ ( "qint8" , np.int8, 1 ) ] )
np.dtype( [ ( "qint8" , np.int8, ( 1 ,)) ] )