概述
目录:
一、windows下anaconda设置国内镜像、pip库下载路径
二、linux下修改默认的py2为py3
三、jupyter notebook修改默认位置
四、jupyter自动代码补全&快捷键操作
五、jupyter notebook中安装R
六、jupyter notebook常用快捷键
--------------------优雅的分割线-------------------
一、设置镜像源&pip库下载路径
1. 由于官网的镜像在境外,访问太慢或者不能访问,为了能够加快访问的速度,更改为国内镜像源。常用镜像有:
阿里云 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/
(1)cmd中输入set,找到USERPROFILE的路径,在其下面建立一个新的文件夹,命名为pip,然后在pip文件夹下面,创建一个命名为pip.ini的文件,输入以下代码:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=tsinghua.edu.cn
(2)conda安装好之后,cmd终端运行:
conda config --add channels Tsinghua Open Source Mirror
conda config --add channels Tsinghua Open Source Mirror
conda config --set show_channel_urls yes
实际更改的文件是位于目录~/.condarc(Linux/Mac)或者C:Users用户名.condarc(Windows)
打开C:Users用户名.condarc(Windows)下面长这样子:
ssl_verify: true
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
(1)和(2)之间貌似没有必然联系,暂未探索其关系。只是看到有相关这种配置,就先放着参考一下吧!
2. 设置pip安装包路径
pip命令安装的包默认安装在C盘,会使C盘占用越来越多。
参考链接:
更改Python的pip install 默认安装依赖路径方法详解www.jb51.net
cmd窗口输入:
python -m site -help
此命令适用于windows和linux,管理这个文件是anaconda目录下的site.py文件,C盘中的python只是它的一个分身而已。linux需要对应进行修改。
找到D:AppInstallanaconda3.5Lib路径下,打开site.py文件,
(1) 设置USER_SITE参数(控制下载的site-packages路径)
USER_SITE = "D:AppInstallanaconda3.5Libsite-packages"
(2) 设置USER_BASE参数(控制执行下载的pip等脚本路径)
USER_BASE = "D:AppInstallanaconda3.5Scripts"
测试一下: pip install jieba试试喽,速度快到飞起来!
如果测试过程会报SyntaxError:<unicode error> 'unicodeescape' codec can`t decode bytes in position 2-3:truncated UXXXXXXXX escape这种错误,需尝试路径前面加r,或者将路径中的“”转换成“”。
二、linux下修改默认的py2为py3
1. 删除旧的python软链接:
sudo rm -rf /usr/bin/python
2. 建立python3的新软链接
ln -s /root/anaconda3/bin/python /usr/bin/python
3. 查看当前使用的python路径。
which python
4. 查看所有python的路径,不止一个。
whereis python
5. 查看python默认版本
python -V
6. 进入python
python
三、jupyter notebook修改默认位置
3.1 修改默认位置
1. 新建一个jupyter notebook的路径,假如是 D:JupyterNotebook
2. cmd中输入下面命令:
jupyter notebook --generate-config
生成jupyter_notebook_config.py文件,并打开对应路径下的此文件,notepad++中找到这一行#c.NotebookApp.notebook_dir = ’ '(大概文件的246行附近),将步骤1生成的路径添加上去,注意一定要去掉前面的#。(#是注释功能)
c.NotebookApp.notebook_dir = ‘D:JupyterNotebook’

保存退出。
3. 确认系统的path路径已经加入D:AppInstallAnaconda37Scripts,此路径下面有jupyter notebook的执行文件。
4. 找到jupyter notebook的快捷方式,右击“属性”:
① 将起始位置修改为步骤1中的路径;
② 将目标中的“%USERPROFILE%”修改成步骤1中的路径"D:JupyterNotebook"

"应用"后点击“确认”。
此时如果在cmd中输入命令:
jupyter notebook
如果可以成功打开浏览器,并且新建一个python3脚本可以运行成功,则表明成功。如果打开新建脚本,但是右上方出现了“kernelerror”,很有可能python的kernel内核路径混乱了。继续往下面看吧!
3.2 处理“kernelerror”
当Anaconda安装多个版本的Python,或由于多次卸载又安装,安装又卸载Anaconda操作,导致python的kernel内核安装路径混乱,使得Jupyter notebook不可用。
解决步骤:
① cmd中输入jupyter kernelspec list
命令查看Jupyter安装的内核和位置;
② 进入python3的核对应安装目录,打开kernel.json, 查看文件中Python的路径是否和安装目录所在的Python环境一致;
③ 若②中路径不一致,切换到安装目录所在Python环境,输入
python -m ipykernel install --user
重新安装内核即可。
笔者并没有直接重新安装内核,而是对应修改了下路径,再重新打开就好了。
四、jupyter自动代码补全&快捷键操作
(1)jupyter自动代码补全
1. 首先安装 nbextensions
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
2. 然后安装 nbextensions_configurator
pip install jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user
用conda安装:
conda install -c conda-forge jupyter_contrib_nbextensions
conda install -c conda-forge jupyter_nbextensions_configurator
或者用pip:
pip install jupyter_nbextensions_configurator jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter nbextensions_configurator enable --user
如果提示缺少依赖,就使用pip安装对应依赖即可。
3. 重启jupyter notebook
在弹出的主页面里,能看到增加了一个Nbextensions标签页,在这个页面里,勾选Hinterland即启用了代码自动补全.
4. pip安装可能遇到的错误:
(4.1) 删除<package name>.egg-info
ERROR: Cannot uninstall 'nbconvert'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
找到enum34.egg-info,一般就在usr/lib/python2.7或者其他安装pythonxxx site-packages等路径里,可以直接在/目录下全局搜索。然后删掉即可。其他的package遇到这种情况方法也通用,搜索<package name>.egg-info,找到后删除即可。
(4.2)Import模块的错误,一般都是模块之间的不兼容问题,特别是tornado>=5.0.0;当jupyter notebook可以正常登陆,打开运行***.ipynb文件时,不能连接服务器,请等待时,根据错误提示,可能需要升级ipykernel、jupyter_和jupyter_core的版本,或者升级其他模块,视具体情况而定。
(4.3)
import win32api ImportError: DLL load failed: 找不到指定的程序。
224、225新版本发布的有问题,回退到223版本即可.。
pip install pywin32=223
(2)jupyter快捷键操作
Jupyter Notebook的27个窍门,技巧和快捷键www.360doc.com(3) 增加可视化插件widgets
pip install ipywidgets --user
jupyter nbextension enable --py --sys-prefix widgetsnbextension
安装ipywidgets过程中,会出现千奇百怪的问题,百度尝试各种解决办法就好了。
(4)jupyter notebook修改主题、字体、字体大小
安装主题:
pip install --upgrade jupyterthemes
查看可用主题:
jt -l
主要设置参数:
-t 设置主题 -f 代码字体 -fs 代码字号 -cellw(占屏比或宽度) -ofs(输出段的字号) -T(显示工具栏)等等。
我的设置:
jt -t oceans16 -f fira -fs 11 -cellw 98% -nfs 10 -tfs 10 -ofs 10 -dfs 10 -T
五、jupyter notebook中安装R
(1) 在R中安装必备包
install.packages(c('rzmq','repr','IRkernel','IRdisplay'),repos = c('IRkernel', getOption('repos')))
(2) 连接R与jupyter
在R Console中输入
IRkernel::installspec()
(3) 刷新jupyter notebook
浏览器中就可以新建R脚本了。
六、jupyter notebook常用快捷键


最后
以上就是鲤鱼月饼为你收集整理的anaconda 安装在c盘_anaconda常用配置的全部内容,希望文章能够帮你解决anaconda 安装在c盘_anaconda常用配置所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复