anaconda自学笔记(Anaconda详细教程)
anaconda自学笔记(Anaconda详细教程)pipinstall--upgradepipwindowscondainfo4、pip4.1 基本命令pip--version#查看版本 pip--help#获取帮助 pipinstall-Upip#升级pip pipinstallpkg#安装包 pipinstallpkg=version#安装指定版本的包 pipinstall--upgradepkg#升级包 pipuninstallpkg#卸载包 pipsearchpkg#搜索包 pipshow#显示安装包信息 pipshow-fpkg#查看指定包的详细信息 piplist#列出已安装的包 piplist-o#查看可升级的包4、2 升级Linux、Maccondaupdateconda condaupdateanaconda condaupdateanaconda-navigator#最新版本的anaconda-navigator3.2
Anaconda介绍、安装及使用教程前言Python是一种面向对象的解释型计算机程序设计语言,具有跨平台的特点,可以在Linux、macOS以及Windows系统中搭建环境并使用,其编写的代码在不同平台上运行时,几乎不需要做较大的改动就能运行。
Python的应用遍及人工智能、科学计算、Web开发、系统运维、大数据及云计算、金融、游戏开发等,具有数量庞大且功能相对完善的标准库和第三方库。
一、Anaconda1、简介Anaconda是大型的科学计算平台,是Python集成开发环境,包含了大量的科学包,能够方便快捷的对程序包进行管理和部署。
2、特点- 安装简单
- 包含了数百个科学模块,高效运用于各种项目
- 免费社区支持
- Anaconda 是跨平台的,有 Windows、macOS、Linux 版本
- 支持多种语言:Python、R、Java等
升级Anaconda需要先升级conda
condaupdateconda
condaupdateanaconda
condaupdateanaconda-navigator#最新版本的anaconda-navigator
3.2 卸载
Linux、Mac 删除安装路径
rm-rfanaconda
3.3 基本命令
conda--version#查看conda版本
condaupdate-nbaseconda#update最新版本的conda
condacreate-nxxxx#创建名为xxxx的虚拟环境
condacreate-nxxxxpython=3.5#创建包含python3.5的名为xxxx的虚拟环境
condaremove-nxxxx--all#删除名为xxxx的虚拟环境
condaactivatexxxx#进入xxxx环境
sourceactivatexxxx
condadeactivate#退出环境
sourceactivate
condaenvlist#显示所有的虚拟环境
condainfo--envs#查看当前环境
condaclean-p#删除没有用的包
condaclean-t#tar打包
condaclean-y-all#删除所有的安装包及cache
3.4 对包的操作
condalist#查看所有已经安装的包
condalist-nxxxx#指定查看xxxx虚拟环境下安装的package
condainstall-nxxxxxxx#在指定环境中安装xxx包
condaupdatexxx#更新包xxx
condauninstallxxx#卸载包xxx
3.5 镜像源
condaconfig--show#查看已经安装过的镜像源
condaconfig--removechannelsurl#删除url源
condaconfig--addchannels#添加url源
condaconfig--setshow_channel_urlsyes#从channel中安装包时显示channel的url
修改配置文件 ~/.condarc
channels:
-https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
-https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
-https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/
-defaults
show_channel_urls:true
查看是否生效
condainfo
4、pip4.1 基本命令
pip--version#查看版本
pip--help#获取帮助
pipinstall-Upip#升级pip
pipinstallpkg#安装包
pipinstallpkg=version#安装指定版本的包
pipinstall--upgradepkg#升级包
pipuninstallpkg#卸载包
pipsearchpkg#搜索包
pipshow#显示安装包信息
pipshow-fpkg#查看指定包的详细信息
piplist#列出已安装的包
piplist-o#查看可升级的包
4、2 升级
Linux、Mac
pipinstall--upgradepip
windows
python-mpipinstall-Upip
4、3 镜像源
临时使用清华源
pipinstall-ihttps://pypi.tuna.tsinghua.edu.cn/simplesome-package
永久修改
Linux、Mac:~/.pip/pip.conf
windows:C:\Users\xx\pip\pip.ini
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里云 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/
[install]
trusted-host = mirrors.aliyun.com
二、安装
官网地址:https://www.anaconda.com/
1、Windows安装时一般默认就行,在Advanced Installation Options这一步,不要勾选Add Anaconda to my PATH environment variable
命令行安装
bash~/Downloads/Anaconda3-5.0.1-MacOSX-x86_64.sh
- 安装过程中,出现提示Press Enter to confirm the location Press CTRL-C to cancel the installation or specify an alternate installation directory.
- 如果接受默认安装路径,则会显示 PREFIX=/home/<user>/anaconda<2 or 3> 并且继续安装。
- 出现提示Do you wish the installer to prepend the Anaconda install location to PATH in your /home/<user>/.bash_profile ?
- 建议输入yes。
前面直接下一步
在这,可以点击Change Install Location来改变安装位置。
完成!
点击Anaconda-Navigator的图标,打开
启动成功,说明安装完成。
三、jupyter1、notebook环境配置1.1、Windows打开控制面板->系统->高级系统设置->环境变量,选中系统变量中的path进行添加
在Anaconda安装位置下的的Script目录及Library\bin目录复制进去,如
jupyternotebook--generate-config
2.2、设置密码
jupyternotebookpassword
#这步设置的密码用于浏览器访问时输入
2.3、修改配置文件
Windows
C:\Users\Administrator\.jupyter\jupyter_notebook_config.py
Linux、Mac
vim~/.jupyter/jupyter_notebook_config.py
#前面的#去掉
c.NotebookApp.ip='*'#开启所有的IP访问,即可使用远程访问
c.NotebookApp.open_browser=False#关闭启动后的自动开启浏览器
c.NotebookApp.port=8888#设置端口8888,也可用其他的,比如1080,8080等等
c.NotebookApp.notebook_dir=’‘#设置notebook默认打开的目录
c.PAMAuthenticator.encoding='utf8'#指定utf-8编码,解决读取中文路径或者文件乱码问题
2.4、启动notebook
jupyternotebook#启动notebook
jupyterlab#启动lab
2.5 远程登录
启动notebook之后在浏览器中输入启动是打印的网址或者:
localhost:port/tree#进入jupyternotebook
localhost:port/lab#进入jupyterlab
jupyter在服务器服务器,想在本地浏览器访问时,需要在终端输入命令
ssh-N-Llocalhost:7777:login-0-0.local:12315dengxsh4490@10.100.2.10
注:localhost:7777指定本地浏览器需要输入的地址,login-0-0.local:12315代表服务器运行jupyter时打印的输出信息中的地址
3、jupyter kernel3.1 扩展 R kernelinstall.package('IRkernel')
#displayname指定jupyter中显示的名字
IRkernel::installspec(name='ir32' displayname='R3.2')
3.2 查看kernel
jupyterkernelspeclist
3.3 卸载指定kernel
jupyterkernelspecremovekernel_name
四、jupyter 插件1、jupyter notebook 插件1.1、安装并激活 jupyter_contrib_nbextensions
pipinstalljupyter_contrib_nbextensions
jupytercontribnbextensioninstall--user
1.2、 安装并启用 Jupyter Nbextensions Configurator
pipinstalljupyter_nbextensions_configurator
jupyternbextensions_configuratorenable--user
1.3、conda安装的方式
condainstall-cconda-forgejupyter_contrib_nbextensionscondainstall-c
conda-forgejupyter_nbextensions_configurator
可替代1.1和1.2
完成后,在启动 jupyter notebook后可在浏览器菜单栏中多了一栏
选中想要的插件即可添加
1.4、插件选择Variable Inspector :这是一个查看变量的插件
Table of Contents :自动生成目录插件
Table of Contents :自动生成目录插件
Codefolding: 代码折叠
Autopep8: 自动代码格式优化
AutoSaveTime: 控制脚本的自动保存时间
Hide Input All: 隐藏所有的代码单元,保持所有的输出和 markdown 单元可见
Spellchecker: 对 markdown 单元中的内容进行拼写检查
插件很多,可根据需要添加
2、jupyter lab插件- 点击菜单栏Settings下拉框中的Advanced Settings Editor选项,进入设置页面
- 接着,点击Extension Manager,并且在右边的空白框里填上{'enabled':true},并且按右上角的保存按钮。
- 最后,你会看到Lab右边会出现插件栏的按钮,我已经安装过一些插件
注:安装这些插件需要先安装 node,并将node添加到环境变量中。安装时请注意node版本
2.1、toc这是一个目录插件,安装后就能很方便地在Lab上展示notebook或者markdown的目录。目录可以滚动,并且能展示或隐藏子目录。
https://link.zhihu.com/?target=https://github.com/jupyterlab/jupyterlab-toc
2.2、LaTeX支持在线编辑并预览LaTeX文档。
https://link.zhihu.com/?target=https://github.com/jupyterlab/jupyterlab-latex
2.3、drawio可以在Lab中启用drawio绘图工具,是一款非常棒的流程图工具。
https://link.zhihu.com/?target=https://github.com/QuantStack/jupyterlab-drawio
2.4、variableinspector该插件可以在Lab中展示代码中的变量及其属性,类似RStudio中的变量检查器。
https://link.zhihu.com/?target=https://github.com/lckr/jupyterlab-variableInspector
2.5、go to Definition该插件用于在Lab笔记本和文件编辑器中跳转到变量或函数的定义。
https://link.zhihu.com/?target=https://github.com/krassowski/jupyterlab-go-to-definition
2.6、lsp该插件用于自动补全、参数建议、函数文档查询、跳转定义等。
https://link.zhihu.com/?target=https://github.com/krassowski/jupyterlab-lsp
2.7 spreadsheet该插件用于在Lab上显示excel表格,只读
https://link.zhihu.com/?target=https://github.com/quigleyj97/jupyterlab-spreadsheet
2.8、debugger可用于试调
condainstallxeus-python=0.8.0-cconda-forge
jupyterlabextensioninstall@jupyterlab/debugger
https://github.com/jupyterlab/debugger
2.9、matplotlib、dash、plotly等可交互式绘图帮助我们在notebook界面配合matplotlib实现交互式的作图,只需要在绘图之前执行魔法命令%matplotlib widget
matplotlib:https://github.com/matplotlib/ipympl
plotly:https://github.com/plotly/plotly.py
2.10、kite在jupyter lab使用kite代码补全服务
https://github.com/kiteco/jupyterlab-kite