Pelican安装使用

  • 安装依赖
#依赖库,写入到requirements.txt
Markdown
pelican
jupyter
ipython
nbconvert
beautifulsoup4
ghp-import
matplotlib
| => pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting Markdown==2.6.6 (from -r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/14/eb/ae35c7d154eb9395c49950788e738effd0e2e8293544e8ee7558a369d7e8/Markdown-2.6.6.zip (412kB)
    100% |████████████████████████████████| 419kB 3.4MB/s
Collecting pelican==3.6.3 (from -r requirements.txt (line 2))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d0/57/d6bba50602b6345ff992b543b904c82f5bac35d84c86949f742bb83dd61d/pelican-3.6.3-py2.py3-none-any.whl (130kB)
    100% |████████████████████████████████| 133kB 7.4MB/s
Requirement already satisfied: jupyter>=1.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from -r requirements.txt (line 3)) (1.0.0)
Requirement already satisfied: ipython>=4.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from -r requirements.txt (line 4)) (6.2.1)
Requirement already satisfied: nbconvert>=4.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from -r requirements.txt (line 5)) (5.3.1)
Requirement already satisfied: beautifulsoup4 in /Users/micocube/Library/Python/3.6/lib/python/site-packages (from -r requirements.txt (line 6)) (4.6.0)
Collecting ghp-import==0.4.1 (from -r requirements.txt (line 7))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/08/17/9847c2be67ef5af9d10835610c59138b37229e0cb296899bdafb4dbd603d/ghp-import-0.4.1.tar.gz
Collecting matplotlib==1.5.1 (from -r requirements.txt (line 8))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8f/f4/c0c7e81f64d5f4d36e52e393af687f28882c53dcd924419d684dc9859f40/matplotlib-1.5.1.tar.gz (54.0MB)
    100% |████████████████████████████████| 54.0MB 538kB/s
    Complete output from command python setup.py egg_info:
    ============================================================================
    Edit setup.cfg to change the build options

    BUILDING MATPLOTLIB
                matplotlib: yes [1.5.1]
                    python: yes [3.6.1 (v3.6.1:69c0db5050, Mar 21 2017,
                            01:21:04)  [GCC 4.2.1 (Apple Inc. build 5666) (dot
                            3)]]
                  platform: yes [darwin]

    REQUIRED DEPENDENCIES AND EXTENSIONS
                     numpy: yes [version 1.13.1]
                  dateutil: yes [using dateutil version 2.6.1]
                      pytz: yes [using pytz version 2017.2]
                    cycler: yes [using cycler version 0.10.0]
                   tornado: yes [using tornado version 4.5.1]
                 pyparsing: yes [using pyparsing version 2.2.0]
                    libagg: yes [pkg-config information for 'libagg' could not
                            be found. Using local copy.]
                  freetype: no  [The C/C++ header for freetype2 (ft2build.h)
                            could not be found.  You may need to install the
                            development package.]
                       png: yes [version 1.6.34]
                     qhull: yes [pkg-config information for 'qhull' could not be
                            found. Using local copy.]

    OPTIONAL SUBPACKAGES
               sample_data: yes [installing]
                  toolkits: yes [installing]
                     tests: yes [nose 0.11.1 or later is required to run the
                            matplotlib test suite. Please install it with pip or
                            your preferred tool to run the test suite / using
                            unittest.mock]
            toolkits_tests: yes [nose 0.11.1 or later is required to run the
                            matplotlib test suite. Please install it with pip or
                            your preferred tool to run the test suite / using
                            unittest.mock]

    OPTIONAL BACKEND EXTENSIONS
                    macosx: yes [installing, darwin]
                    qt5agg: no  [PyQt5 not found]
                    qt4agg: no  [PySide not found; PyQt4 not found]
                   gtk3agg: no  [Requires pygobject to be installed.]
                 gtk3cairo: no  [Requires cairocffi or pycairo to be installed.]
                    gtkagg: no  [Requires pygtk]
                     tkagg: yes [installing, version not identified]
                     wxagg: no  [requires wxPython]
                       gtk: no  [Requires pygtk]
                       agg: yes [installing]
                     cairo: no  [cairocffi or pycairo not found]
                 windowing: no  [Microsoft Windows only]

    OPTIONAL LATEX DEPENDENCIES
                    dvipng: no
               ghostscript: no
                     latex: no
                   pdftops: no

    OPTIONAL PACKAGE DATA
                      dlls: no  [skipping due to configuration]

    ============================================================================
                            * The following required packages can not be built:
                            * freetype

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/2f/6g9vp18j7t15np9rtwvcwxb40000gn/T/pip-install-3xca87ts/matplotlib/
  • 缺少freetype

    • 安装
    | ~/Documents/notebook @ micodeMacBook-Pro (micocube)
    | => brew install freetype
    Updating Homebrew...
    Warning: freetype 2.9 is already installed
    | => brew list freetype
    # free type 已经安装
    /usr/local/Cellar/freetype/2.9/bin/freetype-config
    /usr/local/Cellar/freetype/2.9/include/freetype2/ (49 files)
    /usr/local/Cellar/freetype/2.9/lib/libfreetype.6.dylib
    /usr/local/Cellar/freetype/2.9/lib/pkgconfig/freetype2.pc
    /usr/local/Cellar/freetype/2.9/lib/ (2 other files)
    /usr/local/Cellar/freetype/2.9/share/aclocal/freetype2.m4
    /usr/local/Cellar/freetype/2.9/share/man/man1/freetype-config.1
    
    • 下载matplotlib的源码包(tar.gz格式):下载地址
    • 解压后进入源码目录,执行python3 setup.py,还是说缺少freetype,搜索这个东西到底是在哪报的:
    | => grep -Ilr "freetype" ./
    .//INSTALL
    .//CHANGELOG
    .//setupext.py
    .//matplotlibrc.template
    .//examples/pylab_examples/font_table_ttf.py
    .//lib/matplotlib/backends/backend_pdf.py
    .//lib/matplotlib/backends/backend_agg.py
    .//lib/matplotlib/tests/test_delaunay.py
    .//lib/matplotlib/tests/test_tightlayout.py
    .//lib/matplotlib/testing/decorators.py
    .//lib/matplotlib/mpl-data/matplotlibrc
    .//lib/matplotlib/mpl-data/fonts/ttf/RELEASENOTES.TXT
    .//lib/matplotlib/mpl-data/stylelib/classic.mplstyle
    .//lib/mpl_examples/pylab_examples/font_table_ttf.py
    .//doc/devel/testing.rst
    .//doc/devel/MEP/MEP14.rst
    .//doc/users/text_intro.rst
    .//doc/users/github_stats.rst
    .//doc/users/screenshots.rst
    .//doc/glossary/index.rst
    .//doc/mpl_examples/pylab_examples/font_table_ttf.py
    .//extern/agg24-svn/include/agg_rasterizer_compound_aa.h
    .//extern/agg24-svn/include/agg_rasterizer_cells_aa.h
    .//extern/agg24-svn/include/agg_rasterizer_scanline_aa.h
    .//extern/agg24-svn/include/agg_rasterizer_scanline_aa_nogamma.h
    .//src/ft2font_wrapper.cpp
    .//src/ft2font.h
    .//src/ft2font.cpp
    
    • 最终在setupext.py里找到了检测的源码
    # 抛错的地方
    def check_include_file(include_dirs, filename, package):
    """
    Raises an exception if the given include file can not be found.
    """
    if not has_include_file(include_dirs, filename):
        raise CheckFailed(
            "The C/C++ header for %s (%s) could not be found.  You "
            "may need to install the development package." %
            (package, filename))
    # 基础文件夹
    def get_base_dirs():
    """
    Returns a list of standard base directories on this platform.
    """
    if options['basedirlist']:
        return options['basedirlist']
    
    basedir_map = {
        'win32': ['win32_static', ],
        'darwin': ['/usr/local/', '/usr', '/usr/X11',
                   '/opt/X11', '/opt/local'],
        'sunos5': [os.getenv('MPLIB_BASE') or '/usr/local', ],
        'gnu0': ['/usr'],
        'aix5': ['/usr/local'],
        }
    return basedir_map.get(sys.platform, ['/usr/local', '/usr'])
    # include 文件夹
    def get_include_dirs():
    """
    Returns a list of standard include directories on this platform.
    """
    include_dirs = [os.path.join(d, 'include') for d in get_base_dirs()]
    include_dirs.extend(
        os.environ.get('CPLUS_INCLUDE_PATH', '').split(os.pathsep))
    return include_dirs
    # 检测freetype的代码
    class FreeType(SetupPackage):
    name = "freetype"
    
    def check(self):
        if sys.platform == 'win32':
            check_include_file(get_include_dirs(), 'ft2build.h', 'freetype')
            return 'Using unknown version found on system.'
    
        status, output = getstatusoutput("freetype-config --ftversion")
        if status == 0:
            version = output
        else:
            version = None
    
        # Early versions of freetype grep badly inside freetype-config,
        # so catch those cases. (tested with 2.5.3).
        if version is None or 'No such file or directory\ngrep:' in version:
            version = self.version_from_header()
        if version is None or 'No such file or directory\ngrep:' in version:
            version = self.version_from_header()
    
        # pkg_config returns the libtool version rather than the
        # freetype version so we need to explicitly pass the version
        # to _check_for_pkg_config
        return self._check_for_pkg_config(
            'freetype2', 'ft2build.h',
            min_version='2.3', version=version)
    
    def version_from_header(self):
        version = 'unknown'
        ext = self.get_extension()
        if ext is None:
            return version
        # Return the first version found in the include dirs.
        for include_dir in ext.include_dirs:
            header_fname = os.path.join(include_dir, 'freetype.h')
            if os.path.exists(header_fname):
                major, minor, patch = 0, 0, 0
    def add_flags(self, ext):
        pkg_config.setup_extension(
            ext, 'freetype2',
            default_include_dirs=[
                'include/freetype2', 'freetype2',
                'lib/freetype2/include',
                'lib/freetype2/include/freetype2'],
            default_library_dirs=[
                'freetype2/lib'],
            default_libraries=['freetype', 'z'])
            
    class FT2Font(SetupPackage):
    name = 'ft2font'
    
    def get_extension(self):
        sources = [
            'src/ft2font.cpp',
            'src/ft2font_wrapper.cpp',
            'src/mplutils.cpp'
            ]
        ext = make_extension('matplotlib.ft2font', sources)
        FreeType().add_flags(ext)
        Numpy().add_flags(ext)
        return ext
    
    • mac 上的基础地址是['/usr/local/', '/usr', '/usr/X11','/opt/X11', '/opt/local'],那么选一个,给freetype建立软链接.
      • 已经知道freetype2的存放地址是/usr/local/Cellar/freetype/2.9/include/freetype2/,
      • 建立软链接:ln -s /usr/local/opt/freetype/include/freetype2/freetype2/ft2build.h /usr/local/include/ft2build.h
      • 建立软链接:ln -s /usr/local/opt/freetype/include/freetype2/freetype2/freetype /usr/local/include/freetype
    • 重新执行pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
  • pelican-quickstart

  • git init

  • Pelican doesn't support writing blog posts using Jupyter by default — we'll need to install a plugin that enables this behavio:git submodule add git://github.com/danielfrg/pelican-ipynb.git plugins/ipynb

  • In order to activate the plugin, we'll need to modify pelicanconf.py and add these lines at the bottom:

MARKUP = ('md', 'ipynb')
PLUGIN_PATH = './plugins'
PLUGINS = ['ipynb.markup']
  • 在content文件夹创建一个jupyter notebook文件(.ipynb),同时创建一个同名的.nbdata:
Title: First Post
Slug: first-post
Date: 2016-06-08 20:00
Category: posts
Tags: python firsts
author: Vik Paruchuri
Summary: My first post, read it to find out.
  • First, enable the "metacell" mode globally in your config
IPYNB_USE_METACELL = True
  • Now, you can put the metadata in the first notebook cell in Markdown mode, like this:
    - title: My notebook
    - author: John Doe
    - date: 2018-05-11
    - category: pyhton
    - tags: pip
    
  • 生成html
    • Switch to the jupyter-blog(content的上层目录) folder.
    • Run pelican content to generate the HTML.
    • Switch to the output directory.
    • Run python -m pelican.server.
    • Visit localhost:8000 in your browser to preview the blog.
  • 主题安装
    • 查看已安装的主题和主题保存路径pelican-themes -v -l
    • git clone https://github.com/getpelican/pelican-themes.git ./themes/
    • pelican-themes --install ./themes/bootstrap2 --verbose
    • 编辑 pelicanconf.py,添加THEME = "bootstrap2"
    • 卸载主题命令pelican-themes --remove 主题名称 --verbose
    • 建立软连接安装pelican-themes --symlink ./themes/bootstrap2 --verbose
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,509评论 6 504
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,806评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,875评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,441评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,488评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,365评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,190评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,062评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,500评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,706评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,834评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,559评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,167评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,779评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,912评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,958评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,779评论 2 354

推荐阅读更多精彩内容