Ubuntu – How to install the gedit markdown-preview plugin on 14.04

14.04geditpluginspython

I've just installed the markdown preview plugin for gedit and I get the following error on the console when I try to activate it in the plugins tab:

Traceback (most recent call last): File
"/home/aarold/.local/share/gedit/plugins/markdown-preview/init.py",
line 25, in
import markdown ImportError: No module named 'markdown'

(gedit:20735): libpeas-WARNING **: Error loading plugin
'markdown-preview

Note that this is not the same question as the other one about gedit since its solution does not work for me.

I've tried setting the Loader parameter in my /home/aarold/.local/share/gedit/plugins/markdown-preview.plugin file to python and python3 as well but none of them work. I tried reinstalling the plugin with all possible permutations of options and although it says install was succesful I always get this error. What could be the problem?

I've checked the .py file and it seems that it cannot

import markdown.

Do I need to install some additional python modules?

I've tried

pip install markdown

but although it

Successfully installed markdown

I still get the same error.

Best Answer

This plugin is written for Python 2, but since gedit 3.8, only Python 3 plugins are supported. So some small changes are required.

  1. Modify the installer (gedit-markdown.sh) to install the python3 markdown module:

    This is a patch that you can apply on the existing file (or you can just copy the full modified version available here):

    --- gedit-markdown_ori.sh   2014-05-14 16:14:58.386700310 +0200
    +++ gedit-markdown.sh   2014-05-14 15:42:21.038783248 +0200
    @@ -263,7 +263,9 @@
    
     # Note: sous Archlinux, «/usr/bin/python» correspond à Python 3. On teste donc les
     # chemins pour Python 2 en premier.
    -if type -p python2.7 > /dev/null; then
    +if type -p python3 > /dev/null; then
    +   binPython=$(type -p python3)
    +elif type -p python2.7 > /dev/null; then
        binPython=$(type -p python2.7)
     elif type -p python2.6 > /dev/null; then
        binPython=$(type -p python2.6)
    @@ -287,15 +289,15 @@
                cheminPythonMarkdown=python-markdown/python2
                cheminPythonSitePackages=$("$binPython" -m site --user-site)
            fi
    -#  elif [[ ${versionPython:0:1} == 3 ]]; then
    -#      compareVersions "$versionPython" "3.1"
    -#      
    -#      if [[ $? == 2 ]]; then
    -#          bonneVersionPython=false
    -#      else
    -#          cheminPythonMarkdown=python-markdown/python3
    -#          cheminPythonSitePackages=$("$binPython" -m site --user-site)
    -#      fi
    +   elif [[ ${versionPython:0:1} == 3 ]]; then
    +       compareVersions "$versionPython" "3.1"
    +       
    +       if [[ $? == 2 ]]; then
    +           bonneVersionPython=false
    +       else
    +           cheminPythonMarkdown=python-markdown/python3
    +           cheminPythonSitePackages=$("$binPython" -m site --user-site)
    +       fi
        else
            bonneVersionPython=false
        fi
    
  2. Run ./gedit-markdown.sh install

    You should see python 3.4 instead of 2.7:

    ############################################################
    ##
    ## Installation of gedit-markdown
    ##
    ############################################################
    
    ## First step: check dependencies
    
    - gedit: 3.10.4
    - Python: 3.4
    
    [...]
    
  3. Change the plugin loader to python3

    Replace /home/aarold/.local/share/gedit/plugins/markdown-preview.plugin with:

    [Plugin]
    Loader=python3
    Module=markdown-preview
    IAge=3
    Name=Markdown Preview
    Name[fr]=Aperçu Markdown
    Description=Show the HTML version of the Markdown text you're editing
    Description[fr]=Affiche l'aperçu en HTML du document Markdown en cours d'édition
    Authors=Michele Campeotto <micampe@micampe.it>\nJean-Philippe Fleury <contact@jpfleury.net>
    Copyright=Copyright © 2005, 2006 Michele Campeotto\nCopyright © 2009, 2011-2012 Jean-Philippe Fleury
    Website=http://www.jpfleury.net/logiciels/gedit-markdown.php
    
  4. Convert /home/aarold/.local/share/gedit/plugins/markdown-preview/__init__.py to python3:

    Run:

    2to3 -w /home/aarold/.local/share/gedit/plugins/markdown-preview/__init__.py
    

    Finally open this file and edit line 86 (remove the binary mode, "wb" -> "w"):

    with open(confFile, "w") as confFile:
    
  5. Activate the plugin in Gedit as you did.

Related Question