Pyplot in Python Console: “RuntimeError: 'path' must be None or a list, not <class '_frozen_importlib_external._NamespacePath'>”

I tried to import `pyplot` with `import matplotlib.pyplot as plt` in `Pycharm` via Python Console (set as default in my interpreter options) and I got this error log:

Traceback (most recent call last):
File "/home/sharon/miniconda3/envs/myenv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3343, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-df7889833d14>", line 1, in <module>
runfile('/home/sharon/Desktop/Python/Primrose Bootcamp/week_3/day_1/gradient_descent.py', wdir='/home/sharon/Desktop/Python/Primrose Bootcamp/week_3/day_1')
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/sharon/Desktop/Python/Primrose Bootcamp/week_3/day_1/gradient_descent.py", line 2, in <module>
import matplotlib.pyplot as plt
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/home/sharon/miniconda3/envs/myenv/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2343, in <module>
install_repl_displayhook()
File "/home/sharon/miniconda3/envs/myenv/lib/python3.7/site-packages/matplotlib/pyplot.py", line 155, in install_repl_displayhook
ip.enable_gui(ipython_gui_name)
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 156, in enable_gui
return real_enable_gui(gui, app)
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/pydev_ipython/inputhook.py", line 536, in enable_gui
return gui_hook(app)
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/pydev_ipython/inputhook.py", line 174, in enable_qt
from pydev_ipython.qt_for_kernel import QT_API, QT_API_PYQT5
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/pydev_ipython/qt_for_kernel.py", line 115, in <module>
QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts)
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/pydev_ipython/qt_loaders.py", line 258, in load_qt
if not can_import(api):
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/pydev_ipython/qt_loaders.py", line 146, in can_import
if not has_binding(api):
File "/home/sharon/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/211.7628.24/plugins/python-ce/helpers/pydev/pydev_ipython/qt_loaders.py", line 114, in has_binding
imp.find_module('QtCore', mod.__path__)
File "/home/sharon/miniconda3/envs/myenv/lib/python3.7/imp.py", line 270, in find_module
"not {}".format(type(path)))
RuntimeError: 'path' must be None or a list, not <class '_frozen_importlib_external._NamespacePath'>

Now I did some testing, when I run the file regularly without the Python Console (the regular execution) it run without any problems, I tried to import it in `VS Code` (which uses the same `conda env`) and it worked too, seems like there is a conflict with running it via Python Console, did anyone face this issue before? and btw I'm running `Linux`.

Edit: importing *just* matplotlib doesn't prompt this issue.

1 comment
Comment actions Permalink

Fixed by uninstalling conda & installing anaconda

1

Please sign in to leave a comment.