Why matplotlib is not working on the VSCode

  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Matplotlib
Click For Summary

Discussion Overview

The discussion revolves around an issue with running a basic matplotlib plotting code in Visual Studio Code (VSCode). Participants explore potential reasons for the ImportError encountered during execution, focusing on installation issues and naming conflicts.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • The original poster reports an ImportError when trying to import matplotlib, despite reinstalling Python and VSCode.
  • One participant suggests that the issue may not be with the code itself, as it works on their machine, and proposes reinstalling the matplotlib module or checking for updates.
  • The same participant notes a potential naming conflict due to a file named "copy.py" in the user's directory, which could interfere with the matplotlib import.
  • Another participant agrees with the identification of the naming conflict and humorously advises to avoid using common names to prevent such clashes.

Areas of Agreement / Disagreement

Participants generally agree that the naming conflict with "copy.py" is likely the cause of the issue, but there is no consensus on other potential solutions or the necessity of reinstalling matplotlib.

Contextual Notes

The discussion highlights the importance of file naming conventions in programming, particularly in Python, where module names can clash with user-defined files.

Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
I wrote a basic plotting code and I run it on the VS code my somehow the program cannot run it

I deleted python itself and VS code and I downloaded them again, but the problem is not solved.

Python:
    import matplotlib.pyplot as plt
    x = [1,2,3]
    y = [4,5,6]
    plt.plot(x,y)
    plt.show()

Python:
    Traceback (most recent call last):
    File "c:/Users/xxx/Desktop/Cmpt Physics/dreams.py", line 1, in <module>
        import matplotlib.pyplot as plt
    File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\__init__.py", line 138, in <module>
        from . import cbook, rcsetup
    File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\rcsetup.py", line 24, in <module>
        from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
    File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\fontconfig_pattern.py", line 18, in <module>
        from pyparsing import (Literal, ZeroOrMore, Optional, Regex, StringEnd,
    File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\pyparsing.py", line 104, in <module>       
        import copy
    File "c:\Users\xxx\Desktop\Cmpt Physics\copy.py", line 5, in <module>
        from pylab import plot,show,grid
    File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\pylab.py", line 1, in <module>
        from matplotlib.pylab import *
    File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\pylab.py", line 218, in <module>
        from matplotlib.dates import (
    File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\dates.py", line 156, in <module>
        from matplotlib import rcParams
    ImportError: cannot import name 'rcParams' from 'matplotlib' (C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\__init__.py)

Any idea why this happens ?
 
Technology news on Phys.org
It worked on my machine so its not the program.

Perhaps you need to reinstall the matplotlib module or see if there are updates that need to be installed.

Are you using Anaconda or some other scheme to install py modules?
 
jedishrfu said:
It worked on my machine so its not the program.

Perhaps you need to reinstall the matplotlib module or see if there are updates that need to be installed.

Are you using Anaconda or some other scheme to install py modules?
I realized that I have a file name "copy.py" so it was clashing with the matplotlip module.
 
Ahh okay that explains it. Bad programmer!

One rule of thumb is to always misspell things to prevent clashes with keywords and other stuff.
 
  • Like
Likes   Reactions: Arman777
jedishrfu said:
Ahh okay that explains it. Bad programmer!

One rule of thumb is to always misspell things to prevent clashes with keywords and other stuff.
makes sense, thanks for the tip.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 9 ·
Replies
9
Views
10K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
9
Views
4K
  • · Replies 15 ·
Replies
15
Views
8K
Replies
5
Views
16K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K