[环境搭建八] 深度学习环境搭建--常见问题解决方案汇总

1.在windows系统下, IDLE启动错误,spyer打不开,jupyter打不开,出现连接不上,python.exe,pythonw.exe已停止工作等错误。
在这里插入图片描述

法1:关闭Windows防火墙,若错误消失,说明防火墙阻止了程序启动python.exe和pythonw.exe。
具体操作:控制面板-windows防火墙-允许程序或功能通过windows防火墙-允许运行另一程序-浏览-定位到python或Anaconda安装目录,选中python.exe,打开-添加-确定。同理把pythonw.exe也添加进去,spyter和jupyter也可以打开了。

在这里插入图片描述
2.jupyter不能自动打开浏览器,打开之后一直这样,只能通过复制链接到浏览器打开。
在这里插入图片描述

解决办法:
(1)首先打开Anoconda Prompt,输入命令 jupyter notebook --generate-config,系统会自动产生一个名为jupyter_notebook_config.py的文件,并且Anoconda Prompt窗口中会给出文件的路径。
(2)按着显示的路径找到jupyter_notebook_config.py文件,使用pycharm、记事本、Notepad等打开。
(3)找到c.NotebookApp.password =‘ ’,在下一行输入:(其中C:\Program Files (x86)\Google\Chrome\Application\chrome.exe,这是你想要使用的浏览器路径,可通过右键点击浏览器快捷方式查看属性得到,chrome是你的浏览器名称,可修改,修改完成后保存。标点全部改为英文)
(4)特别注意用户名称不能为中文。

# 1.使用谷歌浏览器
import webbrowser
webbrowser.register('chrome', None, webbrowser.GenericBrowser(u'C:\Program Files(x86)\Google\Chrome\Application\chrome.exe'))
c.NotebookApp.browser = 'chrome'
# 2.使用QQ浏览器
import webbrowser
webbrowser.register('QQBrowser',None,webbrowser.GenericBrowser(u'D:\QQBrowser\QQBrowser.exe'))
c.NotebookApp.browser = 'QQBrowser'

在这里插入图片描述
2.附:如果jupyter保存文件的路径中含有中文,也会出现只闪一下黑屏,然后没有反应的情况。
3.连接镜像报错:

 一直报两个错误
 Could not fetch URL https://pypi.python.org/simple/: connection error: HTTPSConnectionPool(host='pyp
 Could not find a version that satisfies the requirement scikit-learn==0.19.1 (from versions: ) 

解决方案:
使用国内的镜像
pip install pymongo -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
其中,–trusted-host pypi.douban.com 这是为了获得ssl证书的认证

4.安装CPU版的tensorflow

pip install tensorflow==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

检验:

import tensorflow as tf
tf.__version__
输出:版本号
下面只适用于1.x:
x=tf.constant(1)
y=tf.constant(2)
z=x+y
sess=tf.Session()
print(sess.run(z))
输出:3

5.安装tensorflow成功,但是import导入时报错:

import tensorflow
D:\Users\11247\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:517: 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)])
D:\Users\11247\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:518: 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_quint8 = np.dtype([("quint8", np.uint8, 1)])
D:\Users\11247\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:519: 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_qint16 = np.dtype([("qint16", np.int16, 1)])
D:\Users\11247\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:520: 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_quint16 = np.dtype([("quint16", np.uint16, 1)])
D:\Users\11247\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:521: 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_qint32 = np.dtype([("qint32", np.int32, 1)])
D:\Users\11247\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:526: 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_resource = np.dtype([("resource", np.ubyte, 1)])

原因:tensorflow和numpy不兼容不兼容(最终版本tf1.7+numpy1.15)
解决:
查看numpy版本:pip show numpy
安装新的numpy:pip install numpy==1.15.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
依次查找,最终找到合适的版本

6.导入tensorflow报错:
在这里插入图片描述

解决:
重装低版本的tensorflow,重新导入时出现 ModuleNotFoundError: No module named ‘gast’。
pip unstall gast
pip install gast
提示:您安装的gast0.3.0和tensorflow版本不匹配,建议gast0.2.0
pip install gast==0.2.0

7.安装CPU版本的pytorch

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda install pytorch torchvision cpuonly 

8.更改jupyter保存文件路径

第一步:找到配置文件
菜单中打开Anaconda Prompt
输入命令 jupyter notebook --generate-config
根据上面运行处的路径打开C:\Users\HS.jupyter\jupyter_notebook_config.py文件
第二步:更改配置
(1)找到 #c.NotebookApp.notebook_dir = ‘’,去掉该行前面的“#”;在打算存放文件的位置先新建一个文件夹(很重要,最好是英文的),然后将新的路径设置在单引号中,保存配置文件。
(2)在开始菜单找到“Jupyte Notebook”快捷键,鼠标右击 – 更多 – 打开文件位置
找到对应的“Jupyte Notebook”快捷图标,鼠标右击 – 属性 – 目标,去掉后面的 “%USERPROFILE%/”(很重要),然后点击“应用”,“确定” 。重新启动Jupyte Notebook即可。

在这里插入图片描述
在这里插入图片描述
9.安装GPU的pytorch
(1)首先我们要确定本机是否有独立显卡。在计算机-管理-设备管理器-显示适配器中,查看是否有独立显卡。进网站搜索查找是否支持。
(2)查找电脑支持的CUDA:控制面板->搜索NVIDIA->双击进入NVIDIA控制面板:点击帮助->系统信息->组件:或者直接win+q搜索。
在这里插入图片描述
(3)选择CUDA进行安装:地址
在这里插入图片描述
(4)安装CUDA
双击打开,显示临时解压目录,不需要改变,默认就好。
选择自定义的安装方式,并将VS勾给去掉,便可以正常安装了,至于CUDA的安装目录,大家默认安装在C盘即可。
在这里插入图片描述
(5)配置环境变量
在这里插入图片描述
(6)测试
cmd中输入:nvcc -V
在这里插入图片描述
(7)CUDNN的下载及配置。地址。选择的CUDNN的版本要跟CUDA版本一致。
下载之后,解压缩,将CUDNN压缩包里面的bin、clude、lib文件直接复制到CUDA的安装目录下,直接覆盖安装即可。
在这里插入图片描述
(8) 安装torch和torchvision

conda install pytorch torchvision cudatoolkit=10.0

(9)检验

import torch
import torchvision as tv
print(torch.__version__)
print(tv.__version__)
print(torch.cuda.is_available())

10.anaconda创建虚拟环境失败,CondaHTTPError问题
conda httperror http none none for url none Anaconda

方法1: 在conda安装好之后,默认的镜像是官方的,由于官网的镜像在境外,访问太慢或者不能访问,为了能够加快访问的速度,这里选择了清华的的镜像。在命令行中运行(设置清华的镜像)

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

然后,找到C:user/.condarc文件,删除-defaults一行。

方法2: 如果仍然错误的话,将channels:下的链接更新为https://mirror.tuna.tsinghua.edu.cn/help/anaconda/连接下的anconda源,比如:

conda config --remove channels 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/'
conda config --remove channels 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/'
conda config --remove channels 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/'
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/

11.anaconda下安装网上爬虫selenium库,并配置环境
(1)安装selenium库。

conda install selenium

(2)下载谷歌浏览器和驱动
谷歌浏览器:https://www.google.cn/chrome/
查看谷歌浏览器版本:双击打开谷歌,右上角设置,选择帮助,关于谷歌,查看版本。
安装对应版本的驱动:http://npm.taobao.org/mirrors/chromedriver/(只需要大类相同就行,win32位的驱动也适合64位系统)
(3)将解压后的chromedriver文件夹下的exe,直接复制到anconda的安装目录下。
(4)打开编辑器测试一下,如果可以正常打开网页说明,安装成功。

import selenium
print(selenium.__version__)

#用 Chrome 浏览器来测试
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://www.baidu.com/')
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值