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

"NameError: name '_' is not defined" running ipymd from commandline #87

Closed
dmhowcroft opened this issue Dec 14, 2017 · 7 comments
Closed

Comments

@dmhowcroft
Copy link
Contributor

Hi @rossant,

It seems you already discovered this problem (jupyter/notebook#3056 (comment)), but the version of ipymd currently on PyPI and available through pip does not handle this correctly for commandline conversion of ipynb files to Markdown.

Sample attempt:

$ ipymd --from notebook --to markdown my-jupyter-notebook.ipynb 
Traceback (most recent call last):
  File "/home/USER/.local/bin/ipymd", line 7, in <module>
    from ipymd.core.scripts import main
  File "/home/USER/.local/lib/python3.6/site-packages/ipymd/__init__.py", line 3, in <module>
    from .core.contents_manager import IPymdContentsManager
  File "/home/USER/.local/lib/python3.6/site-packages/ipymd/core/contents_manager.py", line 28, in <module>
    from notebook.services.contents.filemanager import FileContentsManager
  File "/home/USER/.local/lib/python3.6/site-packages/notebook/services/contents/filemanager.py", line 21, in <module>
    from .manager import ContentsManager
  File "/home/USER/.local/lib/python3.6/site-packages/notebook/services/contents/manager.py", line 38, in <module>
    class ContentsManager(LoggingConfigurable):
  File "/home/USER/.local/lib/python3.6/site-packages/notebook/services/contents/manager.py", line 70, in ContentsManager
    untitled_notebook = Unicode(_("Untitled"), config=True,
NameError: name '_' is not defined

However, I haven't had any problems when running notebooks already saved as Markdown from within a Jupyter notebook session or saving these.

From that jupyter/notebook thread, I take it you just need to add the bit about transutils to the commandline script.

Version information:

$ pip3 show ipymd
Name: ipymd
Version: 0.1.3
Summary: Use the IPython notebook as an interactive Markdown editor
Home-page: https://github.com/rossant/ipymd
Author: Cyrille Rossant
Author-email: cyrille.rossant at gmail.com
License: BSD
Location: /home/howcroft/.local/lib/python3.6/site-packages
Requires: pyyaml

$ pip3 show notebook
Name: notebook
Version: 5.2.2
Summary: A web-based notebook environment for interactive computing
Home-page: http://jupyter.org
Author: Jupyter Development Team
Author-email: jupyter@googlegroups.com
License: BSD
Location: /home/howcroft/.local/lib/python3.6/site-packages
Requires: tornado, jupyter-client, terminado, traitlets, jinja2, nbconvert, ipykernel, jupyter-core, nbformat, ipython-genutils

@dmhowcroft
Copy link
Contributor Author

Just confirmed: editing core/contents_manager.py to insert the following before line 28 makes it start working:

    from notebook import transutils

So we now have:

try:
    from notebook import transutils
    from notebook.services.contents.filemanager import FileContentsManager
except ImportError:
    from IPython.html.services.contents.filemanager import FileContentsManager

instead of

try:
    from notebook.services.contents.filemanager import FileContentsManager
except ImportError:
    from IPython.html.services.contents.filemanager import FileContentsManager

@rossant
Copy link
Owner

rossant commented Dec 14, 2017

Thanks! would you consider proposing a pull request?

@dmhowcroft
Copy link
Contributor Author

Sorry for not replying sooner. I could do a pull request, but for a one line addition I figured it'd be faster to just tell you about it rather than fussing with forking the project and creating a pull request and all that.

@jdanbrown
Copy link
Contributor

I also ran into this, so I created a PR as per the fix above: #89

@dmhowcroft
Copy link
Contributor Author

Awesome! Thanks :)

@fnl
Copy link

fnl commented Feb 18, 2018

FYI: still happens (to me) when using the pip version of ipymd

@rossant
Copy link
Owner

rossant commented Feb 19, 2018

I have yet to do a new release, you can pip install git+https://github.com/rossant/ipymd.git --upgrade in the meantime

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

No branches or pull requests

4 participants