conda使用教程
1.安裝miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh ;bash ./Miniconda3-latest-Linux-x86_64.sh;
2.配置configure
~/.condarc
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
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/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ #pytorch需要
conda config --set show_channel_urls yes
conda config --remove-key channels #恢復默認鏡像
3.查看已配置的channels
conda config --get channels
4.創建環境和安裝包
conda create -n env_name package_name # 創建env_name環境以及在該環境下安裝package_name包
source activate env_name, source deactivate env_name # 激活或者禁用當前環境
conda info --env,conda env list # 查看所有的環境,帶*的為激活的環境
conda create -n env_name python=3.5 # 在env_name 環境中指定暗轉python3.5版本
conda list # 列出當前環境下所有安裝包
conda list -n my_env # 列出 my_env環境中所有的安裝包
conda list --export > package-list.txt # 把當前環境中的所有包導出list,以備后續使用
conda create -n my_env --file package-list.txt # 對導出的包list重新安裝到my_env 環境中
conda search package_name # 搜索是否有這個安裝包,沒有的話無法使用conda install 安裝
source activate env_name; # conda install package_name,在env_name環境中安裝包
conda info -e #顯示環境信息
conda env remove -n env_name #刪除環境
例如: 創建外顯子測序流程中測序分析環境wes,並在wes中安裝外顯子分析相關軟件,安裝完畢后activate環境即可在該環境下分析wes,以避免軟件沖突
conda create -n wes bcftools vcftools python=2 bwa
source activate wes
5. 刪除環境
conda env remove -n env_name
6.conda安裝/卸載當前channels中不存在的包
anaconda search -t conda xxx #首先搜索包和對應的channel,注意這里是anaconda,而不是conda
anaconda show rpetit3/aspera-connect #查看包詳情
conda install -c rpetit3 aspera-connect #安裝rpetit3 channel中的aspera-connect包
7.更新和卸載包
conda update package_name
conda uninstall package_name, conda remove package_name
conda uninstall -n env package_name # 刪除env環境中的xxx包 uninstall可以用remove代替
conda update --all #更新所有包
8.conda 更新
1 conda update conda
conda配置文件
~/.condarc
channels:
- "'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main'"
- "'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free'"
- "'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro'"
- defaults
show_channel_urls: true
envs_dirs:
- /conda_envs
pkgs_dirs:
- /conda_pkgs
conda安裝Jupyterlab
安裝juperlab
1、在開始菜單中打開Anaconda Prompt
2、執行jupyter lab安裝命令:conda install nodejs jupyterlab
3、升級jupyter內核和客戶端:conda update jupyter_core jupyter_client
4、啟動jupyter lab:jupyter lab
啟動jupyter notebook:jupyter notebook
配置
配置密碼
1.進入python命令行模式
from notebook.auth import passwd
passwd()
輸入方便你記的密碼,連續輸;兩次..輸完密碼后,會輸出一個字符串,形如: ’sha1:9e7a5c5e0a29:8cbdvsv2344d141c92beab1c5bc6e9avsdvdsvsv’將其保存下來, 完成以上操作后,通過exit()退出ipython環境
2.進入安裝目錄 .../jupyter
執行
jupyter lab --generate-config
#命令會產生配置文件:/home/xxx/.jupyter/jupyter_notebook_config.py
3.編輯配置文件
c.NotebookApp.ip = '*' # 允許訪問此服務器的 IP,星號表示任意 IP
c.NotebookApp.password = u'sha1:xxx:xxx' # 之前生成的密碼 hash 字串
c.NotebookApp.open_browser = False # 運行時不打開本機瀏覽器
c.NotebookApp.port = 8888 # 使用的端口,隨意設置
c.NotebookApp.enable_mathjax = True # 啟用 MathJax
c.NotebookApp.allow_remote_access = True #允許遠程訪問
c.NotebookApp.notebook_dir = '/home/xxxx/notebook' #默認打開的工作目錄
4.打開防火牆
firewall-cmd --zone=public --add-port=8888/tcp --permanent
firewall-cmd --query-port=8888/tcp
firewall-cmd --reload
5.啟動服務
#前台運行模式(命令行窗口不能關閉)
jupyter lab
#后台運行模式
nohup jupyter lab &
6.安裝插件
-
安裝nodejs
conda install -c conda-forge nodejs
-
打開ExtensionManager
給Jupyterlab安裝C++ kernel
https://blog.csdn.net/weixin_37543731/article/details/99254107
https://blog.csdn.net/jxncxgx/article/details/104576319
Jupyterlab 插件
https://zhuanlan.zhihu.com/p/101070029
- 顯示系統信息https://www.ctolib.com/mip/jtpio-jupyterlab-system-monitor.html X
- go_to_definition插件
- toc插件https://github.com/jupyterlab/jupyterlab-toc
- autoversion插件 X
- drawio插件
- githubhttps://github.com/jupyterlab/jupyterlab-github
- LaTeXhttps://github.com/jupyterlab/jupyterlab-latex
- HTMLhttps://github.com/mflevine/jupyterlab_htmlX
- plotlyhttps://link.zhihu.com/?target=https%3A//github.com/jupyterlab/jupyter-renderers
- bokehhttps://link.zhihu.com/?target=https%3A//github.com/bokeh/jupyter_bokeh
- matplotlibhttps://github.com/matplotlib/ipympl X
- sqlhttps://github.com/pbugnion/jupyterlab-sql
- variableinspectorhttps://github.com/lckr/jupyterlab-variableInspector X
- gatherhttps://github.com/microsoft/gather
- lsphttps://github.com/krassowski/jupyterlab-lsp
- spreadsheethttps://github.com/quigleyj97/jupyterlab-spreadsheet
Jupyter notebook插件
插件安裝
#pip
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
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
Jupyter notebook 常用快捷鍵
命令行模式
f //查找並替換
x //剪切代碼塊
c //復制代碼塊
v //粘貼到下面
shift-v //粘貼到上面
d //刪除代碼塊
z //撤銷刪除
shift-up/down //擴展選擇單元格
shift-m //合並單元格
y //變成代碼塊
m //變成markdown
r //清楚代碼塊格式
shift-enter //運行並選擇下面代碼塊
alt-enter //運行並插入下面代碼塊
ctrl-enter //運行選中的代碼塊
shift-space //向上滾動
space //向下滾動
編輯模式
CTRL+shift+'-' //切割換行
常用插件
-
autopep8:代碼規范化
-
codefolding:代碼帶折疊效果
-
latexenvironments...:latex支持
-
hinterland:代碼提示
exclude_regexp: /[%0-9a-z._/\\:~-]/i //避免自動上屏
-
highlight select word: 選高亮下文相同單詞
-
table of contenes:toc目錄生成
-
variable inspector:檢查變量
-
autoscroll:自動折疊過長輸出
-
execute time:顯示執行時間
-
notify:長期任務后台通知插件
-
highlighter:markdown高亮
-
jupyterthemes:主題色彩
// https://github.com/dunovank/jupyter-themes jt -t onedork -fs 95 -altp -tfs 11 -nfs 115 -cellw 88% -T