n xxxxx numpy pandas
conda install xxx
4 更新包/也可以更新python的版本
# 更新package
conda update numpy # 更新numpy(当前活跃的环境)
conda update -n xxxxx numpy # 更新指定xxxxx环境下的numpy
conda update python # 假设当前环境是python3.4, conda会将python升级为3.4.x系列的最新版本
5 删除包
# 删除环境package
conda uninstall numpy
conda remove numpy # 删除numpy包(当前活跃的环境)
conda remove -n xxxxx numpy # 删除xxxxx环境下的包
6 彻底卸载anaconda (如果卸载不干净,下一次安装的时候可能会出现报错)
2.1 pip install 和conda install 的区别【link】
二者装的东西不在一个地方
conda install xxx:这种方式安装的库都会放在anaconda3/pkgs
目录下,这样的好处就是,当在某个环境下已经下载好了某个库,再在另一个环境中还需要这个库时,就可以直接从pkgs目录下将该库复制至新环境而不用重复下载。
pip install xxx:分两种情况,一种情况就是当前conda环境的python是conda安装的,和系统的不一样,那么xxx会被安装到anaconda3/envs/current_env/lib/python3.x/site-packages
文件夹中,如果当前conda环境用的是系统的python,那么xxx会通常会被安装到~/.local/lib/python3.x/site-packages
文件夹中
三 与jupyter建立连接
1 Jupyter的安装需要ipython
已经安装有ipython,则直接进行Jupiter的安装
没有安装ipython,使用Anaconda进行python环境的安装
1 在已激活的环境下下载ipykernel
conda install ipykernel
2 建立连接:
python -m ipykernel install --user --name (your_env_name)
3 查看是否连接成功:
jupyter kernelspec list
4 如果没有jupyter,下载jupyter
conda install jupyter notebook
三 打开jupyter notebook
1 win +R 快速打开‘运行’ 对话框,输入cmd ,回车
2 直接输入
jupyter notebook
会直接打开默认路径 。等待一点时间,会自动跳到浏览器;直接输入jupyter notebook [文件路径] 也可以。
注意:黑窗口不能关掉,才能保证anaconda的运行
在jupyter打开指定文件夹的方法:
1、win+R 启动“运行” ,输入cmd 点确定
2、输入cd /d xxxxxxx然后 回车,如:我想打开D:\Git\the-craft-of-selfteaching目录,就输入cd /d D:\Git\the-craft-of-selfteaching,然后回车
3、输入jupyter notebook,回车,jupter notebook便会跳转至指定目录D:\Git\the-craft-of-selfteaching
四 jupyter notebook如何切换环境
1. 激活对应的环境
source activate xxxx
2. 然后安装ipykernel
conda install ipykernel(conda install -c anaconda ipykernel)
3.然后执行
python -m ipykernel install --user --name 环境名称 --display-name "Python (环境名称)"
4.再次启动jupyter notebook
五 使用教程
六 查看jupyter notebook每个单元格运行时间
%%time :(计算执行该单元cell的时间)
%%timeit:(计算执行该单元cell的时间)
%time :(计算当前行的时间 )CPU time(CPU运行程序的时间), Wall time(Wall Clock Time,墙上挂钟的时间,也就是我们感受到的运行时间)。
%timeit:(计算当前行的时间 )计时更为精确,这一命令会运行代码 r 次,每次 n 遍,再对 n*r 遍的结果取平均后,得到运行一遍代码的时间。
1.打开anaconda-jupyter notebook,看有没有Nbextensions选项,如图
2.如果有,请跳过步骤2。
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
3.打开Nbextensions,左上方的disable不勾选,检索time,勾选ExecuteTime。
七 遇到问题
问题一:Original error was: DLL load failed: 找不到指定的模块。
解决方案: 不能直接打开jupyter notebook,激活环境后进入报错消失。