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

ModuleNotFoundError caused from inside lpips #49

Closed
timothybrooks opened this issue Sep 28, 2020 · 5 comments
Closed

ModuleNotFoundError caused from inside lpips #49

timothybrooks opened this issue Sep 28, 2020 · 5 comments

Comments

@timothybrooks
Copy link
Contributor

Any idea why importing lpips is causing this error? It seems to be something from the IPython import causing issues. The ipython (and prompt_toolkit) versions are both the latest release. It works fine within an IPython notebook, but importing lpips inside my training job causes this crash.

Traceback (most recent call last):
  File "run_train.py", line 8, in <module>
    import models
  File "/home/timbrooks/code/prototypes/models/__init__.py", line 2, in <module>
    from .model import *
  File "/home/timbrooks/code/prototypes/models/model.py", line 18, in <module>
    import lpips
  File "/home/timbrooks/anaconda3/envs/prototypes/lib/python3.8/site-packages/lpips/__init__.py", line 11, in <module>
    from lpips.trainer import *
  File "/home/timbrooks/anaconda3/envs/prototypes/lib/python3.8/site-packages/lpips/trainer.py", line 11, in <module>
    from IPython import embed
  File "/home/timbrooks/anaconda3/envs/prototypes/lib/python3.8/site-packages/IPython/__init__.py", line 56, in <module>
    from .terminal.embed import embed
  File "/home/timbrooks/anaconda3/envs/prototypes/lib/python3.8/site-packages/IPython/terminal/embed.py", line 16, in <module>
    from IPython.terminal.interactiveshell import TerminalInteractiveShell
  File "/home/timbrooks/anaconda3/envs/prototypes/lib/python3.8/site-packages/IPython/terminal/interactiveshell.py", line 21, in <module>
    from prompt_toolkit.formatted_text import PygmentsTokens
ModuleNotFoundError: No module named 'prompt_toolkit.formatted_text'
@timothybrooks
Copy link
Contributor Author

If needed, as a workaround you can check for being inside an IPython notebook:

# Automatically detects IPython vs. normal python.
# https://github.com/tqdm/tqdm/blob/master/tqdm/autonotebook.py
try:
    get_ipython = sys.modules["IPython"].get_ipython  # type: ignore
    if "IPKernelApp" not in get_ipython().config:
        raise ImportError("Not inside an IPython notebook.")
except:
    _IN_IPYTHON = False
else:
    _IN_IPYTHON = True
    import IPython
if _IN_IPYTHON:
    # Use IPython here.

@richzhang
Copy link
Owner

richzhang commented Sep 28, 2020

Thanks for pointing that out. I was using them for debugging but they're not necessary. I'll update the pip install. In the meantime, dirty hack is you can remove the from IPython import embed statements from the .py files in "/home/timbrooks/anaconda3/envs/prototypes/lib/python3.8/site-packages/lpips/

@richzhang
Copy link
Owner

Okay, I updated everything: https://pypi.org/project/lpips/0.1.3/. pip install lpips -U should hopefully do it

@timothybrooks
Copy link
Contributor Author

Thanks for the quick fix, Richard!

@timothybrooks
Copy link
Contributor Author

Confirmed that its working now.

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

2 participants