Matplotlib pycharm ошибка

Я совсем новичок в python, и столкнувшись с этой проблемой я не могу продолжать обучение. Вот что происходит когда я запускаю код в Pycharm
введите сюда описание изображения

Ну и после того как я нажимаю на «Закрыть программу» в логе выскакивает «Process finished with exit code -1073741819 (0xC0000005)».
После этого я удалял проект, делал новый, пару раз саму библиотеку удалял и устанавливал, ничего не помогло. Потом я попытался скачать эту библиотеку без помощи Pycharm, вроде все хорошо, но как только пытаюсь запустить этот же код в Geany, Python тут же прекращает работу.
До этого работал с библиотекой pygame и все работало отлично, а сейчас не знаю.
Еще хочу добавить что ошибки еще были в тот момент, когда я первый раз скачивал эту библиотеку.
P.S. я выяснил, что проблема именно в строке «import matplotlib.pyplot»
Для лучшего понимания вопроса вот серия скриншотов:
1. Удаляю matplotlib Удаляю matplotlib с помощью консоли
2. Снова скачиваю matplotlib c помощью pipвведите сюда описание изображения
3. Запускаю код. Ошибкавведите сюда описание изображения
4. Окей, создаю новый проектвведите сюда описание изображения
5. Скачиваю matplotlib с помощью Pycharm введите сюда описание изображения
6. Импортирую matplotlib, та же ошибка, скриншот прикреплять не буду

I have installed PyCharm with Anaconda. I installed numpy fine using the PyCharm settings by adding the package via the Project Interpreter tab. However I am now trying to install matplotlib and I get a list of errors.

Just by including the line

import matplotlib.pyplot as plt

I get the errors:

AttributeError: module 'matplotlib.pyplot' has no attribute 'switch_backend'
Matplotlib support failed
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 23, in do_import
    succeeded = activate_func()
  File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\_pydev_bundle\pydev_console_utils.py", line 199, in <lambda>
    "matplotlib": lambda: activate_matplotlib(self.enableGui),
  File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\pydev_ipython\matplotlibtools.py", line 96, in activate_matplotlib
    gui, backend = find_gui_and_backend()
  File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\pydev_ipython\matplotlibtools.py", line 47, in find_gui_and_backend
    backend = matplotlib.rcParams['backend']
  File "C:\Users\calcl\Anaconda3\envs\PXP\lib\site-packages\matplotlib\__init__.py", line 892, in __getitem__
    plt.switch_backend(rcsetup._auto_backend_sentinel)

What could be causing this problem and how would I resolve it?

I am using Python 3.6 with 3.0.0 Matplotlib and PyCharm 2018.2.4

If you’re a data scientist or Python developer, you’ve likely encountered the PyCharm import error claiming that ‘matplotlib’ is not a package, even though it works perfectly in IDLE. This issue can be frustrating, especially when you’re in the middle of a project. In this blog post, we’ll guide you through the steps to resolve this common problem.

PyCharm Import Error: Solving the ‘matplotlib’ Package Issue

If you’re a data scientist or Python developer, you’ve likely encountered the PyCharm import error claiming that ‘matplotlib’ is not a package, even though it works perfectly in IDLE. This issue can be frustrating, especially when you’re in the middle of a project. In this blog post, we’ll guide you through the steps to resolve this common problem.

Understanding the Issue

Before we dive into the solution, it’s important to understand the problem. The error message 'matplotlib' is not a package typically arises when PyCharm fails to recognize the installed ‘matplotlib’ package. This can happen due to several reasons, such as incorrect Python interpreter settings, a conflict between Python versions, or a problem with the ‘matplotlib’ installation.

Step 1: Verify Your Python Interpreter

The first step in resolving this issue is to verify your Python interpreter. PyCharm allows you to configure the Python interpreter at the project level or at the IDE level. If you’re using the wrong interpreter, PyCharm might not be able to locate the ‘matplotlib’ package.

# Check your Python interpreter
import sys
print(sys.executable)

If the output of this command doesn’t match the interpreter you’re using in PyCharm, you’ll need to adjust your settings.

Step 2: Adjust Your PyCharm Interpreter Settings

To adjust your PyCharm interpreter settings, follow these steps:

  1. Go to File > Settings > Project: [your_project_name] > Python Interpreter.
  2. In the Python Interpreter dropdown, select the interpreter that matches the output of sys.executable.
  3. If the correct interpreter isn’t listed, click on the Show All... option and add the correct interpreter.

Step 3: Verify Your ‘matplotlib’ Installation

The next step is to verify your ‘matplotlib’ installation. You can do this by running the following command in your Python interpreter:

# Check your 'matplotlib' installation
import matplotlib
print(matplotlib.__version__)

If this command returns an error, it means that ‘matplotlib’ isn’t installed correctly.

Step 4: Reinstall ‘matplotlib’

If ‘matplotlib’ isn’t installed correctly, you’ll need to reinstall it. You can do this by running the following command in your Python interpreter:

# Reinstall 'matplotlib'
pip uninstall matplotlib
pip install matplotlib

After reinstalling ‘matplotlib’, try importing it again in PyCharm. If you’re still encountering the error, it might be due to a conflict between Python versions.

Step 5: Resolve Python Version Conflicts

If you’re using multiple versions of Python, there might be a conflict that’s causing the import error. To resolve this, you’ll need to ensure that ‘matplotlib’ is installed for the correct Python version. You can do this by specifying the Python version when reinstalling ‘matplotlib’:

# Reinstall 'matplotlib' for a specific Python version
pip3 uninstall matplotlib
pip3 install matplotlib

Conclusion

The PyCharm import error claiming that ‘matplotlib’ is not a package can be a roadblock in your data science projects. However, by following these steps, you should be able to resolve this issue and get back to your work. Remember to verify your Python interpreter, adjust your PyCharm interpreter settings, verify your ‘matplotlib’ installation, reinstall ‘matplotlib’ if necessary, and resolve any Python version conflicts.

If you’re still encountering issues, don’t hesitate to reach out to the Python community for help. There are numerous forums and resources available to assist you in troubleshooting your problems.

Keywords

  • PyCharm import error
  • ‘matplotlib’ is not a package
  • Python interpreter
  • ‘matplotlib’ installation
  • Python version conflicts

About Saturn Cloud

Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Join today and get 150 hours of free compute per month.

In this Python tutorial, we will discuss the modulenotfounderror: no module named ‘matplotlib’  and we shall also cover the following topics:

  • modulenotfounderror: no module named matplotlib windows 10
  • modulenotfounderror: no module named ‘matplotlib’ ubuntu
  • modulenotfounderror no module named ‘matplotlib’ python 3
  • modulenotfounderror no module named ‘matplotlib’ jupyter notebook
  • modulenotfounderror no module named ‘matplotlib’ anaconda
  • modulenotfounderror: no module named ‘matplotlib’ pycharm
  • modulenotfounderror: no module named ‘matplotlib.pyplot’; ‘matplotlib’ is not a package
matplotlib full tutorial

Check if you have pip installed already, simply by writing pip in the Python console. If you don’t have pip, get a Python script called get-pip.py from the internet and save it to your local system. pip is the Python package installer.

Take note of where the file got saved and change the current directory to that directory from the command prompt.

pip  -- Press Enter

-- If you don't have a pip then

cd path_of_directory_of_get-pip_script

Run the get-pip.py script to install pip by writing the following code in cmd (command prompt) to install pip:

"python .\get-pip.py"

Now in cmd type the following code to install matplotlib with its dependencies:

pip install matplotlib

The error will be resolved, if not then follow through the end of this post.

Read: What is Matplotlib

modulenotfounderror: no module named ‘matplotlib’ ubuntu

If you don’t have matplotlib installed then to install Matplotlib for Python 3 through the APT package manager, you need the package python3-matplotlib:

sudo apt-get install python3-matplotlib

If you want to install it with pip for Python 2.7, you need to use pip:

sudo pip install matplotlib

If the error still arises, follow through to the end of the post.

Read: How to install matplotlib

modulenotfounderror no module named ‘matplotlib’ python 3

You can install matplotlib with pip for Python 3 and above, you just need to use pip3.

Open the Python console and execute the command given below:

sudo pip3 install matplotlib

By executing the above code, the matplotlib for your Python will be installed.

modulenotfounderror no module named ‘matplotlib’ jupyter notebook

Create a virtual environment inside your project directory. If you don’t have it, you have to install virtualenv by executing the following command in the cmd/terminal.

virtualenv environment_name   -- environment_name specifies the name of 
                              -- the environment variable created

Install matplotlib inside of your virtual environment.

pip3 install matplotlib

Now, install ipykernel inside your virtual environment.

pip3 install ipykernel

Connect your jupyter kernel to your new environment.

sudo python3 -m ipykernel install

When you start your Jupyter Notebook, you will see the option to select an environment and select the environment you have created that has matplotlib installed. Now, you are good to go with it.

Read: What is a Python Dictionary 

modulenotfounderror no module named ‘matplotlib’ anaconda

If you have Python installed previously, before installing Anaconda, the reason could be that it’s running your default Python installation instead of the one installed with Anaconda. You have to try prepending this to the top of your script:

#!/usr/bin/env python

If that does not work, restart the terminal and try installing matplotlib with conda in conda prompt or cmd, and see if it works.

conda install matplotlib

If the problem is still not resolved, maybe you have to create a virtual environment as given in the above topics.

modulenotfounderror: no module named ‘matplotlib’ pycharm

You can get this error if you are using Pycharm and have matplotlib.py in your current working directory. You have to just delete or rename the matplotlib.py file to resolve the issue, most probably it will work.

modulenotfounderror: no module named ‘matplotlib.pyplot’; ‘matplotlib’ is not a package

The error is caused because of the following reasons, check them out:

  • Make sure that the version of matplotlib you are installing is compatible with your Python version installed.
  • If the python installed is 64 bits version with matplotlib is 32 bits. Make sure they are the same.
  • Make sure to add the PATH variable for system and environment variables with the path to the python.
  • If the pip version is outdated, upgrade it to the latest version.
python -m pip install
  • Also, make sure that there are no typos in the import statement.
  • If the error still exists then, try to check if there is any file matplotlib.py in your working directory. Remove that file, restart the kernel, and import matplotib again. That should work.

You may also like reading the following articles.

  • How to install Django
  • Python Django vs Flask
  • Python NumPy shape
  • module ‘matplotlib’ has no attribute ‘plot’

In this Python tutorial, we have discussed the modulenotfounderror: no module named ‘matplotlib’ and we have also covered the following topics:

  • modulenotfounderror: no module named matplotlib windows 10
  • modulenotfounderror: no module named ‘matplotlib’ ubuntu
  • modulenotfounderror no module named ‘matplotlib’ python 3
  • modulenotfounderror no module named ‘matplotlib’ jupyter notebook
  • modulenotfounderror no module named ‘matplotlib’ anaconda
  • modulenotfounderror: no module named ‘matplotlib’ pycharm
  • modulenotfounderror: no module named ‘matplotlib.pyplot’; ‘matplotlib’ is not a package

Fewlines4Biju Bijay

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.

The modulenotfounderror: no module named ‘matplotlib’ Jupyter error log occurs when the virtual environment cannot locate the module named matplotlib or its package. This instance causes several issues with your Jupyter Notebook project or application that affect the package manager and terminate other processes and functions.No Module Named Matplotlib Modulenotfounderror

In addition, you could experience the modulenotfounderror: no module named ‘matplotlib’ Windows warning when the current Python version does not comply with the requirements from the remote repository, so it cannot render the inputs. Still, this guide teaches how to fix the module named ‘matplotlib’ code exception using advanced debugging techniques and methods that prevent complications with the install matplotlib procedures.

Contents

  • Why Is the No Module Named ‘Matplotlib’ Code Exception Happening?
    • – Running Different Matplotlib Libraries in Python
    • – The Matplotlib Package Is Missing From the Document
  • Fix the No Module Named ‘Matplotlib’ Error Log: Full-Proof Solutions
    • – Correcting the Spec Windows File
    • – Check Your Matplotlib Version
  • Conclusion

Why Is the No Module Named ‘Matplotlib’ Code Exception Happening?

The modulenotfounderror no module named ‘matplotlib’ PyCharm code exception happens because sometimes the system cannot find the module named ‘matplotlib’ or its package. The inconsistency can happen even after the matplotlib installed message appears. In addition, the modulenotfounderror: no module named ‘matplotlib’ Ubuntu bug is inevitable with different versions.

For instance, although the application has several correct modules and elements, a single package named ‘matplotlib’ could compromise the entire project and display the modulenotfounderror no module named ‘matplotlib’ vscode bug. The system experiences the need for such a package when the install pip procedure fails.

As a result, the application indicates the broken inputs and terminates further operations, which could affect other code snippets and commands. Hence, we suggest recreating and demonstrating the modulenotfounderror: no module named ‘matplotlib’ Mac error log using standard elements before implementing the solutions for the module named issue.

However, other confusing instances throw the modulenotfounderror: no module named ‘matplotlib_inline’ mistake, affecting similar inputs. For example, different Python versions or libraries could compromise your programming experience and kill the named matplotlib, although this is atypical with modern programs and applications.

In addition, the modulenotfounderror no module named ‘matplotlib’ but installed message can happen when messing up the configurations in the global or remote IDE, blocking the virtual environment. Hence, we recommend scanning your code and troubleshooting the flawed code snippet before practicing this guide’s debugging techniques and solutions.

– Running Different Matplotlib Libraries in Python

The error log is guaranteed when launching different matplotlib libraries and packages in your Python project. Although this inconsistency does not occur when running the code in your local repository, it can pop up when introducing the remote machine. So, we will exemplify the commands and traceback calls to complete the first broken instance.No Module Named Matplotlib Code Exception

You can learn more about the failed libraries in the following example:

(speech-env) C:\Users\Desktop\app\kivy\spyzer-exe\dist\spyzer>spyzer.exe

[INFO ] [Logger ] Record log in C:\Users\.kivy\logs\kivy_23-11-14_39.txt

[INFO ] [Kivy ] v2.1.2

[INFO ] [Kivy ] Installed at “C:\Users\Desktop\app\kivy\spyzer-exe\dist\spyzer\kivy\__init__.pyc”

[INFO ] [Python ] v3.9.2 (tags/v3.9.1:1e15y33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]

[INFO ] [Python ] Interpreter at “C:\Users\Desktop\app\kivy\spyzer-exe\dist\spyzer\spyzer.exe”

[INFO ] [Logger ] Purge log fired. Processing…

[INFO ] [Logger ] Purge finished!

[INFO ] [Factory ] 1255 symbols loaded

[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)

[INFO ] [Text ] Provider: sdl2

[INFO ] [AudioGstplayer] Using Gstreamer 1.18.5.2

[INFO ] [Audio ] Providers: audio_gstplayer, audio_sdl2 (audio_ffpyplayer ignored)

Lastly, let us exemplify the error log that indicates the flawed processes and stops the application, as shown in the following example:

Traceback (most recent call last):

File “kivy\lang\parser.py”, line 817, in execute_directives

File “<frozen importlib._bootstrap>”, line 1675, in __import__

File “<frozen importlib._bootstrap>”, line 2459, in _gcd_import

File “<frozen importlib._bootstrap>”, line 6175, in _find_and_load

File “<frozen importlib._bootstrap>”, line 9175, in _find_and_load_unlocked

File “<frozen importlib._bootstrap>”, line 125, in _load_unlocked

File “<frozen importlib._bootstrap_external>”, line 557, in exec_module

File “<frozen importlib._bootstrap>”, line 158, in _call_with_frames_removed

File “C:\Users\Desktop\app\kivy\spyzer-exe\dist\spyzer\audio_analysis

Although this is a common cause, other confusing instances and culprits exist.

– The Matplotlib Package Is Missing From the Document

Demonstrating the missing package from the main document is challenging, so we will provide the analysis output to clarify the problems. Therefore, we will first focus on the imported packages from the main configuration. Later, we will list the code exception calls that pinpoint the missing commands and functions. These inputs could resemble the commands in your document.

The following example provides the analysis information:

a = Analysis(

[‘C:\\Users\\Desktop\\app\\kivy\\kivy-speech\\main.py’],

Pathex = [],

Binaries = [],

datas = added_files,

hiddenimports = [],

hookspath = [],

hooksconfig = {},

runtime_hooks = [],

excludes = [],

win_no_prefer_redirects = False,

win_private_assemblies = False,

cipher = block_cipher,

noarchive = False,

)

pyz = PYZ(a.pure, a.zipped_data, cipher = block_cipher)

exe = EXE(

exclude_binaries = True,

name = ‘spyzer’,

debug = False,

bootloader_ignore_signals = False,

strip = False,

upx = True,

console = True,

disable_windowed_traceback = False,

argv_emulation = False,

target_arch = None,

codesign_identity = None,

entitlements_file = None,

)

This code snippet is only complete after listing the error log confirming the flaws and inconsistencies, as explained in the following example:

Traceback (most recent call last):

File “C:\Program Files\Odoo 14.0e.20210518\server\odoo\base\models\ir_http.py”, line 444, in _dispatch

result = request.dispatch()

File “C:\Program Files\Odoo 14.0e.20210518\server\http.py”, line 214, in dispatch

result = self._call_function (**self.params)

File “C:\Program Files\Odoo 14.0e.20210518\server\http.py”, line 145, in _call_function

return checked_call (self.db, *args, **kwargs)

File “C:\Program Files\Odoo 14.0e.20210518\server\service\model.py”, line 22, in wrapper

return f (dbname, *args, **kwargs)

File “C:\Program Files\Odoo 14.0e.20210518\server\http.py”, line 981, in checked_call

result = self.endpoint (*a, **kw)

File “C:\Program Files\Odoo 14.0e.20210518\server\http.py”, line 9124 in __call__

return self.method (*args, **kw)

Nevertheless, after implementing this guide’s debugging techniques and solutions, repairing this error log and its properties is straightforward.

Fix the No Module Named ‘Matplotlib’ Error Log: Full-Proof Solutions

You can fix the no module named matplotlib error log by installing or providing the missing package for the main document. In addition, we suggest correcting the spec Windows file to fit the project’s needs and requirements. Both debugging methods require isolating the incorrect commands.

Alternatively, you can repair your broken project by checking the matplotlib version to ensure it suits the Python program. Nevertheless, practice this technique only after implementing the primary debugging methods. Hence, this section teaches you how to install and provide the missing package for the main document. Finally, you will clarify the path and reenable the virtual environment.

We explained the technique in the following code snippet:

# in a virtual environment or launching Python 2

pip install matplotlib

# for python 3 (could also be pip3.15 depending on your version)

pip3 install matplotlib

# if you get permissions error

sudo pip3 install matplotlib

pip install matplotlib –user

# if you don’t have pip in your PATH environment property

python -m pip install matplotlib

# for python 3 (could also be pip3.15 depending on your version)

python3 -m pip install matplotlib

# using py alias (Windows)

py -m pip install matplotlib

# alternative for Debian (Ubuntu)

sudo apt-get install python3-matplotlib

# alternative for Red Hat / CentOS

sudo yum install python3-matplotlib

# alternative for Fedora

sudo dnf install python3-matplotlib

# alternative for Arch Linux

sudo pacman -S python-matplotlib

# for Anaconda

conda install -c conda-forge matplotlib

# for Jupyter Notebook

!pip install matplotlib

We provided several comments to help you understand the code’s purpose.

– Correcting the Spec Windows File

The error log should disappear after correcting the spec Windows file that confuses the module. As a result, we will provide a simple code snippet with several commands that repair the document and clears the bug. Although you can paste the syntax to your document, changing the values is essential.No Module Named Matplotlib Code Exception

You can learn more about this approach in the following example:

from kivy_deps import sdl2, glew

block_cipher = None

app_name = ‘App Name Here’

win_icon = ‘../Images/my_icon.ico’

a = Analysis ([‘../main.py’],

pathex = [],

binaries = [],

datas = [(‘../*.kv’, ‘.’),

(‘../Images/*.png’, ‘./Images’)],

Hiddenimports = [‘win32timezone’],

Hookspath = [],

runtime_hooks = [],

excludes = [],

win_no_prefer_redirects = False,

win_private_assemblies = False,

cipher = block_cipher,

noarchive = False)

pyz = PYZ (a.pure, a.zipped_data,

cipher = block_cipher)

exe = EXE (pyz,

a.scripts,

[],

exclude_binaries = True,

name = app_name,

debug = False,

bootloader_ignore_signals = False,

strip = False,

upx = False,

console = False,

icon = win_icon)

coll = COLLECT (exe,

a.binaries,

a.zipfiles,

a.datas,

*[Tree (p)

for p in (sdl2.dep_bins + glew.dep_bins)],

strip = False,

upx = False,

name = app_name)

We had to set several true and false values to complete the procedure and correct the code snippet. Lastly, check the matplotlib version to ensure you use the correct one.

– Check Your Matplotlib Version

An interesting get-around method is checking the version to ensure it fits the Python program. This technique takes a minute and works for all operating systems, so it is better to do it than not. In addition, you will get additional information about other system configurations and properties.

The following code snippet exemplifies this procedure:

pip show matplotlib

Name: matplotlib

Version: 3.2.5

Summary: Python plotting package

Home-page: https://matplotlib.org

Author: Bill D. Hunter, Josh Droettboom

Author-email: matplotlib-users@python.org

License: PSFS

Location: /srv/notebook/lib/python3.7/site-packages

Requires: cycler, numpy, kiwisolver, python-dateutil, pyparsing

Required-by: seaborn, scikit-image

Note: you may need to relaunch the kernel to use updated packages

As you can tell, the first code line initiates the procedure that checks your version and provides additional information about your project.

Conclusion

The no module named ‘matplotlib’ code exception happens when the system cannot find the ‘matplotlib’ package. Still, read the following bullet list to remember this guide’s vital points:

  • The warning happens when the current Python version does not adhere to the needs of the remote repository
  • You can fix the no module named matplotlib error log by installing or providing the missing package for the main document
  • Checking your matplotlib version and credential provides essential information about your project

After implementing this guide’s debugging techniques and solutions, no errors or obstacles should stand in your way. Still, remember some code snippets require additional changes and code alterations.

  • Author
  • Recent Posts

Position is Everything

Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL. Meet The Team

Position is Everything

Понравилась статья? Поделить с друзьями:
  • Matplotlib does not support generators as input ошибка
  • Mathcad ошибка значение должно быть целым числом
  • Matlab ошибка лицензии
  • Matlab ошибка 114
  • Matiz ошибка p0335