#!/usr/bin/env python # coding: utf-8 # 在anaconda 环境中运行jupyter notebook # # *** # *** # # 问题及其解决方法 # *** # *** # # # Mac电脑如何快速找到用户目录 #   # - 1、在finder的`偏好设置`中选择`边栏`选中个人收藏下`房子的图标`,然后在边栏就可以看到用户目录,然后就可以找到目录了。 # # - 2、在finder的`偏好设置`中选择`通用`,然后选择`磁盘`,磁盘就出现在桌面了,这样也可以很方便的进入`根目录`,进而找到用户目录; # # - 3、`桌面目录`下,菜单`前往`-`个人`也可以进入`用户目录` # # 如何打开jupyter notebook # # - Mac users: 打开terminal (可以在launchpad中找到),输入:`jupyter notebook` # - windows users: 在电脑左下角输入'cmd'打开terminal, 输入:`jupyter notebook` # # 在terminal里成功安装第三方的包,结果发现在notebook里无法import # > 这个问题多出现于mac用户,因为mac有一个系统自带的python,成功安装的第三方包都被安装到了系统自带的python里。因此需要确保我们使用的是conda自己的pip,即需要指定pip的路径名,比如我的pip路径名在:/Users/datalab/anaconda/bin/pip,那么在terminal里输入: # # > /Users/datalab/anaconda/bin/pip install package_name # - 或者在notebook的初始页面,右上方-new-terminal,在这个terminal里输入 # > **pip install package_name** # - 或者通过anaconda自带的spyder安装 # - 常用的包也可以直接 # > **conda install package_name** # # # 如何查看anaconda自带的包和已经安装的包? # > 打开terminal,输入: conda list # # windows用户安装graphlab-create出错:unistall tornado, permission denied: tornado/speedup.pdy, 解决方法: # - 首先,卸载tornado: # > conda remove tornado # - 然后,重新运行: # > pip install -U graphlab-create # # 添加Anaconda的国内镜像,快速安装Python包 # # **添加清华镜像** # # https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/ # # ```python # conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/ # # conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/ # # conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/ # conda config --set show_channel_urls yes # ``` # # #### 设置搜索时显示通道地址 # > conda config --set show_channel_urls yes # # 如果命令行方法添加不上,可以在用户目录下的`.condarc`中添加https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/: # 如果没有该文件可以直接创建,Windows为`C://Users/username/.condarc`,Linux/Mac为`~/.condarc` # # # To install a different version of Python without overwriting the current version # # https://conda.io/docs/user-guide/tasks/manage-python.html # # Creating a new environment and install the second Python version into it. To create the new environment for Python 2.7, in your Terminal window or an Anaconda Prompt, run: # > conda create -n py27 python=2.7 anaconda=4.0.0 # # ## Activate the new environment ** 切换到新环境** # # - linux/Mac下需要使用: `source activate py27` # - windows需要使用: `activate py27` # # **退出环境: `source deactivate py27` # 也可以使用** `activate root`切回root环境 # # 3. [Verify that the new environment is your current environment.](https://conda.io/docs/user-guide/tasks/manage-environments.html#determine-current-env) # 4. To verify that the current environment uses the new Python version, in your Terminal window or an Anaconda Prompt, run: `python --version` # ## 使用py27环境时的一个例子: # # - 激活py27环境:`source activate py27` # - 打开notebook: `jupyter notebook` # - 关闭py27环境:`source deactivate py27` # # 如何让graphlab在notebook中展示所有的结果(不另外打开新的窗口) # > 运行以下代码 # In[1]: import graphlab as gl from IPython.display import display from IPython.display import Image gl.canvas.set_target('ipynb') # # 如何卸载一个包 # > conda remove package_name # # roll back to a specific commit # # #### open the terminal, and cd to your github repo, e.g., # # > cd github/cjc2016 # # #### git reset --hard , and if your old-commit-id is 3808166 # # > git reset --hard 3808166 # # > git push origin HEAD --force # # http://stackoverflow.com/questions/4372435/how-can-i-rollback-a-github-repository-to-a-specific-commit # # python matplotlib plot 数据中的中文无法正常显示的解决办法 # # 原因:matplotlib默认字体并不是中文字体。 # # 解决方法:将某中文字体设为默认首选字体,本文拟将默认字体设为微软雅黑。 # # 环境:windows # # 过程: # # 在python的安装目录中找到配置文件:%Python_Home%\Lib\site-packages\matplotlib\mpl-data\matplotlibrc,用任意文本编辑器打开。(最好先备份一下) # # 找到第139行:#font.family, 将其注释去掉,冒号后面的值改为Microsoft YaHei # # 找到第151行:#font.sans-serif, 将其注释去掉,并将Microsoft YaHei添加到冒号后面的最前面,注意还要再加一个英文逗号(,) # # 为保险其间,到C:\Windows\Fonts\中找到微软雅黑对应的字体文件msyh.ttf,将其复制到D:\Python32\Lib\site-packages\matplotlib\mpl-data\fonts\ttf\目录下 # # # # python matplotlib plot 数据中的中文无法正常显示的解决办法 # # 原因:matplotlib默认字体并不是中文字体。 # # 解决方法:将某中文字体设为默认首选字体,本文拟将默认字体设为微软雅黑。 # # 环境:Mac # # 过程: # # 1. 下载微软雅黑对应的字体文件msyh.ttf,双击并安装msyh.ttf。 # 2. 在python的安装目录中找到配置文件:%Python_Home%\Lib\site-packages\matplotlib\mpl-data\matplotlibrc,用任意文本编辑器打开。(最好先备份一下) # > Users/datalab/Applications/anaconda/lib/python3.5/site-packages/matplotlib/mpl-data/ # # - 找到第139行:#font.family, 将其注释去掉,冒号后面的值改为Microsoft YaHei # - 找到第151行:#font.sans-serif, 将其注释去掉,并将Microsoft YaHei添加到冒号后面的最前面,注意还要再加一个英文逗号(,) # 1. 为保险期间,可以将msyh.ttf复制到%Python_Home%\Lib\site-packages\matplotlib\mpl-data\fonts\ttf\目录下 # # # In[8]: get_ipython().run_line_magic('matplotlib', 'inline') import matplotlib.pyplot as plt plt.plot(2, 2) plt.text(2, 2, '汉字', fontsize = 300) plt.show() # # Jupyter contrib nbextensions # # - Unofficial Jupyter Notebook Extensions # - A collection of various notebook extensions for Jupyter # # http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/ # # https://github.com/ipython-contrib/jupyter_contrib_nbextensions # # http://localhost:8888/nbextensions # # # Jupyter Nbextensions Configurator # # A jupyter notebook serverextension providing config interfaces for nbextensions. # # https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator # # 前者是各类型有用的插件,后者是能够直接在Jupyter 上图形话调节界面的功能。 # # 输出PDF # # a、安装pandoc # # https://github.com/jgm/pandoc/releases/tag/1.19.2.1 # # b、安装MiKTeX # # https://miktex.org/download # # c、安装 GNU make for windows # # http://gnuwin32.sourceforge.net/packages/make.htm # # d、把上面安装好的软件路径,全部添加到环境变量里面 # # e、PDF支持中文 # # C:\Python27\Lib\site-packages\nbconvert\templates\latex\article.tplx # # 把 \documentclass[11pt]{article} 修改为 \documentclass[11pt]{ctexart} 即可!!! # # # # Pandoc 支持中文 # # pandoc infile.md -o outfile.pdf --latex-engine=xelatex -V mainfont="SimSun" # # END