Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'UnescapeTreeprocessor' from 'markdown.treeprocessors' #474

Closed
AzadKshitij opened this issue Nov 14, 2022 · 7 comments

Comments

@AzadKshitij
Copy link

Getting this error:

D:\temp\exprot>obsidianhtml convert -i config.yaml
> COPYING VAULT D:\My Stuff TO C:\Users\-\AppData\Local\Temp\tmp44oe4onb
Paths that will be ignored: ['D:/My Stuff/.obsidian', 'D:/My Stuff/.trash', 'D:/My Stuff/.DS_Store', 'D:/My Stuff/.git']
< COPYING VAULT: Done
> CLEARING OUTPUT FOLDERS
> CREATING OUTPUT FOLDERS
> COMPILING MARKDOWN FROM OBSIDIAN CODE (C:\Users\azadk\AppData\Local\Temp\tmp44oe4onb\Home.md)
> COMPILING HTML FROM MARKDOWN CODE (D:\temp\exprot\output\md\index.md)
Traceback (most recent call last):
  File "C:\Users\azadk\AppData\Local\Programs\Python\Python310\lib\site-packages\obsidianhtml\ErrorHandling.py", line 59, in _decorator
    res = f(*args, **kwargs)
  File "C:\Users\azadk\AppData\Local\Programs\Python\Python310\lib\site-packages\obsidianhtml\ConvertVault.py", line 1078, in ConvertMarkdownPageToHtmlPage
    html_body = markdown.markdown(md.page, extensions=extensions, extension_configs=extension_configs)
  File "C:\Users\azadk\AppData\Local\Programs\Python\Python310\lib\site-packages\markdown\core.py", line 386, in markdown
    md = Markdown(**kwargs)
  File "C:\Users\azadk\AppData\Local\Programs\Python\Python310\lib\site-packages\markdown\core.py", line 96, in __init__
    self.registerExtensions(extensions=kwargs.get('extensions', []),
  File "C:\Users\azadk\AppData\Local\Programs\Python\Python310\lib\site-packages\markdown\core.py", line 123, in registerExtensions
    ext = self.build_extension(ext, configs.get(ext, {}))
  File "C:\Users\azadk\AppData\Local\Programs\Python\Python310\lib\site-packages\markdown\core.py", line 155, in build_extension
    ext = entry_points[0].load()
  File "C:\Users\azadk\AppData\Local\Programs\Python\Python310\lib\importlib\metadata\__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "C:\Users\azadk\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\azadk\AppData\Local\Programs\Python\Python310\lib\site-packages\obsidianhtml\markdown_extensions\CustomTocExtension.py", line 29, in <module>
    from markdown.treeprocessors import UnescapeTreeprocessor
ImportError: cannot import name 'UnescapeTreeprocessor' from 'markdown.treeprocessors' (C:\Users\azadk\AppData\Local\Programs\Python\Python310\lib\site-packages\markdown\treeprocessors.py)

        OBS.HTML EXTRA ERROR INFORMATION:
        ---------------------------------
        Current action              : Conversion of markdown notes to html notes
        Subroutine                  : ConvertMarkdownPageToHtmlPage
        Current note being processed: D:\temp\exprot\output\md\index.md ()

config.yaml file

# The first folder that contains all obsidian files
# Use full path or relative path, but don't use ~/
obsidian_folder_path_str: "D:/My Stuff" 

# The note that will be used as the index.html 
# should be in obsidian_folder_path_str
# Use full path or relative path, but don't use ~/
obsidian_entrypoint_path_str: "D:/My Stuff/Home.md"
@dwrolvink
Copy link
Collaborator

Can you run the following commands in sequence and share all the output that it generates?

pip uninstall obsidianhtml
pip install obsidianhtml --upgrade 
obsidianhtml version
obsidianhtml convert -i config.yaml

If you are using virtualenvs let me know.

@dwrolvink dwrolvink added the bug Something isn't working label Nov 14, 2022
@Origami404
Copy link

I have the same error too, here is some info:

$ obsidianhtml run -f ./Overview.md
... the same error ...
$ obsidianhtml version
3.3.0
$ python -V
3.10.7

@Origami404
Copy link

Origami404 commented Nov 19, 2022

I figure it out, this package depends on package markdown >= 3.4.1, in which they add UnescapeTreeprocessor. You may need to upgrade the package by:

pip install --upgrade markdown

Upgrading the markdown package solves my problem.

Note that mkdocs depends on markdown < 3.4, so if you are using them both, please considering using a venv. @AzadKshitij

dwrolvink added a commit that referenced this issue Nov 19, 2022
#474 ensure markdown version >= 3.4.1
@dwrolvink dwrolvink added this to the v3.3.0+ milestone Nov 19, 2022
@dwrolvink
Copy link
Collaborator

Thanks Origami! I've added the minimum requirement to the setup.cfg file, and now it enforces the minimum versions when you run pip install ..

This change will come through in obsidianhtml >= 3.4.0

@stories-with-dice
Copy link

I am still getting this error

Python 3.10.6
obsidianhtml==3.3.0
Markdown==3.4.1

Ubuntu

test vault: testvault.zip

(obsidianhtml) ➜  testvault obsidianhtml run -f ~/Documents/testvault/test/Index.md                                                                                                                                                                           
INFO: Config var was set. (provided by user through commandline)                                                                                                                                                                                              
        obsidian_entrypoint_path_str: /home/cristian/Documents/testvault/test/Index.md                                                                                                                                                                        
INFO: Config var was set. (deduced)                                                                                                                                                                                                                           
        obsidian_folder_path_str: /home/cristian/Documents/testvault/test                                                                                                                                                                                     
INFO: Creating tempdir                                                                                                                                                                                                                                        
INFO: Created temporary directory /tmp/obshtml_kah3ngcb                                                                                                                                                                                                       
INFO: Internal config var was set. (provided by user through commandline):                                                                                                                                                                                    
        [internal] output_folder_path: /tmp/obshtml_kah3ngcb                                                                                                                                                                                                  
INFO: Created empty output folder path /tmp/obshtml_kah3ngcb/md                                                                                                                                                                                               
INFO: Config var was set. (default behavior)                                                                                                                                                                                                                  
        md_folder_path_str: /tmp/obshtml_kah3ngcb/md                                                                                                                                                                                                          
INFO: Config var was set. (default behavior)                                                                                                                                                                                                                  
        md_entrypoint_path_str: /tmp/obshtml_kah3ngcb/md/index.md                                                                                                                                                                                             
INFO: Created empty output folder path /tmp/obshtml_kah3ngcb/html                                                                                                                                                                                             
INFO: Config var was set. (default behavior)                                                                                                                                                                                                                  
        html_output_folder_path_str: /tmp/obshtml_kah3ngcb/html                                                                                                                                                                                               
> COPYING VAULT /home/cristian/Documents/testvault/test TO /tmp/tmpm4lf7c0s                                                                                                                                                                                   
running:                                                                                                                                                                                                                                                      
         rsync -a /home/cristian/Documents/testvault/test/ /tmp/tmpm4lf7c0s --exclude /.obsidian/ --exclude /.trash/ --exclude /.DS_Store/ --exclude /.git/                                                                                                   
Copy succeeded 0  b''                                                                                                                                                                                                                                         
< COPYING VAULT: Done                                                                                                                                                                                                                                         
> CLEARING OUTPUT FOLDERS                                                                                                                                                                                                                                     
> CREATING OUTPUT FOLDERS                                                                                                                                                                                                                                     
> COMPILING MARKDOWN FROM OBSIDIAN CODE (/tmp/tmpm4lf7c0s/Index.md)                                                                                                                                                                                           
> COMPILING HTML FROM MARKDOWN CODE (/tmp/obshtml_kah3ngcb/md/index.md)                                                                                                                                                                                       
Traceback (most recent call last):                                                                                                                                                                                                                            
  File "/home/cristian/.local/lib/python3.10/site-packages/obsidianhtml/ErrorHandling.py", line 59, in _decorator                                                                                                                                             
    res = f(*args, **kwargs)                                                                                                                                                                                                                                  
  File "/home/cristian/.local/lib/python3.10/site-packages/obsidianhtml/ConvertVault.py", line 1078, in ConvertMarkdownPageToHtmlPage                                                                                                                         
    html_body = markdown.markdown(md.page, extensions=extensions, extension_configs=extension_configs)                                                                                                                                                        
  File "/usr/lib/python3/dist-packages/markdown/core.py", line 386, in markdown                                                                                                                                                                               
    md = Markdown(**kwargs)                                                                                                                                                                                                                                   
  File "/usr/lib/python3/dist-packages/markdown/core.py", line 96, in __init__                                                                                                                                                                                
    self.registerExtensions(extensions=kwargs.get('extensions', []),                                                                                                                                                                                          
  File "/usr/lib/python3/dist-packages/markdown/core.py", line 123, in registerExtensions                                                                                                                                                                     
    ext = self.build_extension(ext, configs.get(ext, {}))                                                                                                                                                                                                     
  File "/usr/lib/python3/dist-packages/markdown/core.py", line 155, in build_extension                                                                                                                                                                        
    ext = entry_points[0].load()                                                                                                                                                                                                                              
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load                                                                                                                                                                                
    module = import_module(match.group('module'))                                                                                                                                                                                                             
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module                                                                                                                                                                                
    return _bootstrap._gcd_import(name[level:], package, level)                                                                                                                                                                                               
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import                                                                                                                                                                                             
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load                                                                                                                                                                                          
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked                                                                                                                                                                                 
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked                                                                                                                                                                                           
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module                                                                                                                                                                                     
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed                                                                                                                                                                                
  File "/home/cristian/.local/lib/python3.10/site-packages/obsidianhtml/markdown_extensions/CustomTocExtension.py", line 29, in <module>                                                                                                                      
    from markdown.treeprocessors import UnescapeTreeprocessor                                                                                                                                                                                                 
ImportError: cannot import name 'UnescapeTreeprocessor' from 'markdown.treeprocessors' (/usr/lib/python3/dist-packages/markdown/treeprocessors.py)                                                                                                            
                                                                                                                                                                                                                                                              
        OBS.HTML EXTRA ERROR INFORMATION:                                                                                                                                                                                                                     
        ---------------------------------                                                                                                                                                                                                                     
        Current action              : Conversion of markdown notes to html notes                                               
        Subroutine                  : ConvertMarkdownPageToHtmlPage                                                            
        Current note being processed: /tmp/obshtml_kah3ngcb/md/index.md ()

@dwrolvink
Copy link
Collaborator

Can you try to install the latest version (development) and see if you then still have the issue?

pip uninstall obsidianhtml
pip install git+https://github.com/obsidian-html/obsidian-html.git

Working on getting the current master out as a release somewhere this weekend if I can get the open bugs resolved

@dwrolvink
Copy link
Collaborator

Created a new release in the mean time, hence the change in tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants