美文网首页
Pelican安装使用

Pelican安装使用

作者: MicoCube | 来源:发表于2018-09-29 18:34 被阅读0次
    • 安装依赖
    #依赖库,写入到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

    相关文章

      网友评论

          本文标题:Pelican安装使用

          本文链接:https://www.haomeiwen.com/subject/sppboftx.html