Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
1  
Many thanks, this helped me solving my problem (arch derivate) with this plugin; although I also had to remove .decode("utf-8") in __init__.py line 382 because of an AttributeError. It seems that from python3.x this method is removed and 2to3 does not recognize... –  32bitfloat Jun 16 at 22:30
    
@32bitfloat, good to know, thanks for your contribution –  Sylvain Pineau Jun 17 at 7:46
    
I've unisntalled it and try to install it again with the new gedit-markdown.sh but I've a error "Permission not allowed" (Sorry I tried to write a comment) –  Vincent Aug 31 at 11:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.