Skip to content

Importing pyplot messes with command line argument parsing #1986

Closed
@Nikratio

Description

@Nikratio

Consider this:

[0] nelarikon:~/tmp$ cat argparsebug.py
#!/usr/bin/env python

from __future__ import division, print_function, absolute_import
from argparse import ArgumentParser
import matplotlib
import matplotlib.pyplot as plt

parser = ArgumentParser()

parser.add_argument("--name", type=str, default=None,
                    help="Prefix for files to load")

options = parser.parse_args()
print('Name is %s' % repr(options.name))
print('matplotlib version:', matplotlib.__version__)
[0] nelarikon:~/tmp$ ./argparsebug.py --name foo
Name is None
matplotlib version: 1.2.0

Removing the import matplotlib.pyplot as plt line gives the correct output,

[0] nelarikon:~/tmp$ ./argparsebug.py --name foo
Name is 'foo'
matplotlib version: 1.2.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions