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

Wrong error string for mprof plot run #171

Closed
ShahriyarR opened this issue Nov 14, 2017 · 4 comments
Closed

Wrong error string for mprof plot run #171

ShahriyarR opened this issue Nov 14, 2017 · 4 comments
Labels

Comments

@ShahriyarR
Copy link

@ShahriyarR ShahriyarR commented Nov 14, 2017

Hi,

I got the following:

$ mprof plot mprofile_20171114100151.dat
matplotlib is needed for plotting.

But in fact matplotlib is satisfied:

$ sudo pip3.5 install -U matplotlib
Requirement already up-to-date: matplotlib in /usr/lib64/python3.5/site-packages
Requirement already up-to-date: pytz in /usr/lib/python3.5/site-packages (from matplotlib)
Requirement already up-to-date: cycler>=0.10 in /usr/lib/python3.5/site-packages (from matplotlib)
Requirement already up-to-date: numpy>=1.7.1 in /usr/lib64/python3.5/site-packages (from matplotlib)
Requirement already up-to-date: python-dateutil>=2.0 in /usr/lib/python3.5/site-packages (from matplotlib)
Requirement already up-to-date: six>=1.10 in /usr/lib/python3.5/site-packages (from matplotlib)
Requirement already up-to-date: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/lib/python3.5/site-packages (from matplotlib)
>>> import matplotlib
>>> 

From https://github.com/pythonprofilers/memory_profiler/blob/master/mprof#L342

def plot_file(filename, index=0, timestamps=True, children=True, options=None):
    try:
        import pylab as pl
    except ImportError as e:
        print("matplotlib is needed for plotting.")
        print(e)
sys.exit(1)

So it is printing the string but in fact the mprof failed due to:

>>> import pylab
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.5/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/usr/lib64/python3.5/site-packages/matplotlib/pylab.py", line 257, in <module>
    from matplotlib import cbook, mlab, pyplot as plt
  File "/usr/lib64/python3.5/site-packages/matplotlib/pyplot.py", line 113, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/lib64/python3.5/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
    [backend_name], 0)
  File "/usr/lib64/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
    from six.moves import tkinter as Tk
  File "/usr/lib/python3.5/site-packages/six.py", line 92, in __get__
    result = self._resolve()
  File "/usr/lib/python3.5/site-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/usr/lib/python3.5/site-packages/six.py", line 82, in _import_module
    __import__(name)
ImportError: No module named 'tkinter'

Based on this, it will be great to give much more informative error message here.

@astrojuanlu
Copy link
Collaborator

@astrojuanlu astrojuanlu commented Nov 14, 2017

Hello @ShahriyarR, thanks for your bug report! This looks like some installation issue with Python and its dependencies, but we will see. Some comments:

I recommend you to avoid using sudo pip install. You can break your system in a very, very ugly way that can be very difficult to debug. Use virtual environments instead, or pip install --user.

"The first rule of Python is you don't use system Python" pic.twitter.com/ZR3IK4xAo2

— Barry Warsaw (@pumpichank) May 21, 2017

On the other hand, the No module named 'tkinter' is a well known problem when installing matplotlib, see https://stackoverflow.com/q/36327134/554319.

So in fact, you're right that "No module named 'tkinter'" should be printed instead to be more informative. But I see there's already a print(e) line there, so I'm not sure why the full error is not printed. Did you paste the complete output of mprof? If that line is not doing what it's supposed to do we'll have to fix it, otherwise there's not much we can do.

@ShahriyarR
Copy link
Author

@ShahriyarR ShahriyarR commented Nov 14, 2017

Hi @Juanlu001, thanks for tips. I am using test local Vagrant env and it is not too much important to break something :)

Yes I have pasted full output, trying again:

sudo yum remove python35u-tkinter
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package python35u-tkinter.x86_64 0:3.5.4-1.ius.centos7 will be erased
--> Finished Dependency Resolution

The result:

[vagrant@dhcppc3 ~]$ mprof plot
matplotlib is needed for plotting.
[vagrant@dhcppc3 ~]$ 
@astrojuanlu
Copy link
Collaborator

@astrojuanlu astrojuanlu commented May 17, 2018

Related: #91

@astrojuanlu
Copy link
Collaborator

@astrojuanlu astrojuanlu commented May 17, 2018

I tried to reproduce this by creating a conda environment and --force removing tk, and I get this error before installing matplotlib:

$ conda create -n _notk36 python=3.6
$ conda activate _notk36
$ conda remove tk --force
$ pip install memory_profiler
$ mprof plot 
matplotlib is needed for plotting.
No module named 'pylab'

And after installing matplotlib and selecting another backend

$ MPLBACKEND=Qt5Agg mprof plot
matplotlib is needed for plotting.
Matplotlib qt-based backends require an external PyQt4, PyQt5,
PySide or PySide2 package to be installed, but it was not found.

So I think the error message is working as expected, and perhaps you were using an old version of memory_profiler. I am closing this, please comment if the problem persists.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.