需要指定版本和镜像时

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

为什么有镜像
在pip安装包时,包要从服务器上下载到本地后安装,不指定镜像时会选择国外的服务器,速度较慢,指定国内服务器后,速度较快,上面的镜像为清华源

设置永久镜像

%APPDATA%\pip\pip.ini $HOME/.config/pip/pip.conf下建立文件夹pip,在内创建pip.ini,输入以下内容

  1. [global]
  2. index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  3. [install]
  4. trusted-host = https://pypi.tuna.tsinghua.edu.cn

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

https://pip.pypa.io/en/stable/user_guide/
https://mirrors.tuna.tsinghua.edu.cn/help/pypi/

Pip

  1. pip install tensorflow==2.2.0
  2. python3 -m pip install tensorflow==2.2.0
  3. pip freeze > requirements.txt
  4. pip install -r requirements.txt
  1. https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/
  2. conda config --set show_channel_urls yes

envs

  1. conda activate base
  2. conda deactivate
  3. conda create --name your_env_name
  4. conda create --name your_env_name python=3.5
  5. conda create --name your_env_name python=3.5 numpy scipy
  6. conda info --envs
  7. conda env list
  8. conda remove --name your_env_name --all

package

  1. conda list
  2. conda list jupyter*
  3. conda install
  4. conda install package -c anaconda
  5. conda install package --force-reinstall
  6. conda remove package_name
  7. conda update package_name
  8. conda search package_name
  9. conda search package_name --channel https://conda.anaconda.org/<channel-name>/
  10. # original conda url https://conda.anaconda.org/<channel-name>/
  11. conda update –-all

config

  1. conda config --show
  2. conda clean -p //删除没有用的包
  3. conda clean -t //删除tar包
  4. conda clean -y --all //删除所有的安装包及cache

add kernel

  1. conda install -c conda-forge jupyterlab
  2. conda install ipykernel # base下
  3. conda create -n <env_name> python=3.7
  4. conda activate <env_name>
  5. conda install --yes --file requirements.txt
  6. conda env export > freeze.yml
  7. conda env create -f freeze.yml
  8. conda install ipykernel
  9. python -m ipykernel install --user --name <env_name> --display-name "<display_name>"
  10. conda deactivate
  11. jupyter kernelspec list
  12. jupyter kernelspec remove <kernel_name>

add R kernel

  1. install.packages('IRkernel')
  2. IRkernel::installspec() # to register the kernel in the current R installation
  3. jupyter labextension install @techrah/text-shortcuts # for RStudio’s shortcuts

jupyter lab extension

jupyter labextension list

install jupyterlab_code_formatter

  1. conda install -c conda-forge jupyterlab_code_formatter
  2. jupyter labextension install @ryantam626/jupyterlab_code_formatter@1.2.0
  1. 你可以使用pyright mypy pytype pyre

pandoc —standalone —self-contained —css sssimonyang.css 暑假生存录1.md —output 暑假生存录1.html

  1. from IPython.core.interactiveshell import InteractiveShell
  2. InteractiveShell.ast_node_interactivity = "all" # 返回全部显示
  3. # 也可以在!ipython profile create后 C:\Users\sssimonyang\.ipython\profile_default\ipython_config.py 添加c.InteractiveShell.ast_node_interactivity = 'all'
  1. !ipython profile create
  2. [ProfileCreate] Generating default config file: 'C:\\Users\\sssimonyang\\.ipython\\profile_default\\ipython_config.py'
  3. [ProfileCreate] Generating default config file: 'C:\\Users\\sssimonyang\\.ipython\\profile_default\\ipython_kernel_config.py'
  4. [ProfileCreate] Generating default config file: '/slst/home/yangjk/.ipython/profile_default/ipython_config.py'
  5. [ProfileCreate] Generating default config file: '/slst/home/yangjk/.ipython/profile_default/ipython_kernel_config.py'
  1. 修改使用的shell

c.ServerApp.terminado_settings = {‘shell_command’: [‘C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe’]}

  1. 个人未设置成功

IPython 魔法命令 https://ipython.readthedocs.io/en/stable/interactive/magics.html
reset # 删除所有变量
https://juejin.cn/post/6844904056020975629

  1. % matplotlib inline
  2. % matplotlib notebook
  1. from IPython.display import Image
  2. Image(filename = "img/picture.png")
  3. Image(url = '')

jupyter从指定位置启动修改

  1. jupyter notebook --generate-config
  2. Writing default config to: C:\Users\sssimonyang\.jupyter\jupyter_notebook_config.py
  3. Writing default config to: /slst/home/yangjk/.jupyter/jupyter_notebook_config.py
  4. jupyter lab --generate-config
  5. Writing default config to: C:\Users\sssimonyang\.jupyter\jupyter_lab_config.py
  6. jupyter --config-dir
  7. C:\Users\sssimonyang\.jupyter\jupyter_notebook_config.py
  8. c.NotebookApp.notebook_dir = 'D:\\sssimonyang\\projects\\jupyter_lab'
  9. C:\Users\sssimonyang\.jupyter\jupyter_lab_config.py
  10. c.ServerApp.root_dir = 'D:\\sssimonyang\\projects\\jupyter_lab'
  11. jupyter nbconvert --to markdown .\notes\python\python_basic.ipynb
  12. jupyter nbconvert --to pdf .\notes\python\python_basic.ipynb

sns loadataset 问题
在C:\Users\sssimonyang处

  1. git clone https://github.com/mwaskom/seaborn-data
  1. a=2

install jupyterlab extension jupyterlab_code_formatter
I was using JupyterLab < 3.0.0

  1. jupyter labextension install @ryantam626/jupyterlab_code_formatter
  1. jupyter labextension list
  2. JupyterLab v2.2.6
  3. Known labextensions:
  4. app dir: C:\ProgramData\Anaconda3\share\jupyter\lab
  5. @ryantam626/jupyterlab_code_formatter v1.3.8 enabled ok

install package of corresponding version

  1. conda install jupyterlab_code_formatter=1.3.8

then:

  1. jupyter serverextension enable --py jupyterlab_code_formatter

if error:

  1. from jupyter_server.base.handlers import APIHandler
  2. ModuleNotFoundError: No module named 'jupyter_server'

do

  1. conda install -c conda-forge jupyter_server
  1. %ls
  1. 驱动器 D 中的卷没有标签。
  2. 卷的序列号是 D806-799C
  3. D:\sssimonyang\projects\jupyter_lab\notes\python 的目录
  4. 2021/04/09 21:27 <DIR> .
  5. 2021/04/09 21:27 <DIR> ..
  6. 2021/04/09 20:54 <DIR> .ipynb_checkpoints
  7. 2021/04/09 21:07 36,882 python_advance.ipynb
  8. 2021/04/09 21:24 47,772 python_basic.ipynb
  9. 2021/03/20 21:08 9,346 python_config.ipynb
  10. 2021/04/09 21:23 250,135 python_data_analysis.ipynb
  11. 2021/04/09 20:19 792 python_ipython.ipynb
  12. 2021/04/09 21:27 3,844 python_notes.md
  13. 2021/04/09 21:27 15,695 python_package.ipynb
  14. 2021/04/09 21:14 10 some.txt
  15. 8 个文件 364,476 字节
  16. 3 个目录 54,786,064,384 可用字节
  1. from IPython.display import Image
  2. Image(url = '')
  3. %load_ext autoreload
  4. %autoreload 2