Как добавить matplotlib в pycharm
Перейти к содержимому

Как добавить matplotlib в pycharm

  • автор:

Ошибка импорта 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, та же ошибка, скриншот прикреплять не буду

Отслеживать

Splish_Splash

задан 7 окт 2019 в 15:28

Splish_Splash Splish_Splash

120 6 6 бронзовых знаков

А если нажать «Показать подробности», что там?

7 окт 2019 в 16:55

@МарияРиваненкова там ничего особенного, «имя приложения : python.exe», и другая информация которая не дает четкого представления о проблеме, но к счастью я уже смог решить

Setup Matplotlib on PyCharm

Matplotlib is an effective Python library for producing static, animated, and interactive visualizations in a variety of forms. For data analysis, scientific study, and various other uses, it offers a flexible and effective approach to constructing plots, charts, and graphs. It is built on NumPy arrays, designed to work with the broader SciPy stack, and consists of several plots like lines, bars, scatters, histograms, etc. Matplotlib is often used for a wide variety of applications because it is extremely flexible and provides an extensive range of graphing options.

Important Features Matplotlib

  1. Basic Plotting: Using Matplotlib, we can produce numerous basic plot types, including line plots, scatter plots, bar charts, histograms, and more.
  2. Customization: You can alter the colors, line styles, labels, titles, and annotations of your plots using Matplotlib.
  3. Subplots: It is easy to show different visualizations in a single plot by creating different plots within the same figure.

Setup Matplotlib on PyCharm

Below are the ways by which we can install Matplotlib on PyCharm :

  • Using Terminal
  • Using PyCharm GUI

Install Matplotlib Using Terminal

Below is the step-by-step procedure to install Matplotlib using Terminal:

Step 1: Installation

The first step is installation. We will install the following things that you can refer for their installation:

Step 2: Create a Virtual Environment

It is the next step after the installation. In this step, we will create a virtual environment for managing project-specific dependencies and avoiding conflicts between different projects. You can refer here : Create a Virtual Environment .

Step 3: Install Matplotlib via PyCharm Terminal

Now that the virtual environment is activated, we can now install Matplotlib using the pip command. Open command-prompt or the built-in terminal in PyCharm and run the following command to install the Matplotlib library.

pip install matplotlib

Screenshot-(249)

To prevent any errors during the matplotlib installation process, just make sure that “pip” is installed and updated to the most recent version on your system.

Setup Matplotlib via PyCharm GUI

To install Matplotlib using PyCharm’s (GUI), follow the steps given below:

Step 1: Create a New Python Project

Create a new Python project or open an existing one in PyCharm. You should be working within a project to manage your Python packages.

Step 2: Select Settings or Preferences:

Now first go to “File” in the top menu then select “Settings” or “Preferences” (depending on your operating system).

Screenshot-2023-10-26-224056

Step 3: Select Python Interpreter

In the settings window, expand the “Project” section on the left sidebar and select “Python Interpreter.” In the “Python Interpreter” window, you’ll see a list of installed packages and the current Python interpreter for your project. Click the ” + ” button or “Install” button to add a new package. This will open the package window showing available packages.

Screenshot-2023-10-26-224157

Menu showing Installed libraries and packages

Step 4: Write Matplotlib

In the “Available Packages” window, type “matplotlib” in the search bar. It will display “matplotlib” in the list of packages. Select it. If an older version of the packages is needed for your project, you can also select it by clicking the drop down of “Specify version”.

Screenshot-2023-10-26-230434-(1)

Selecting Matplotlib from Available Packages

Step 5: Install the Package

Click the “Install Package” button to install Matplotlib. Matplotlib and its dependencies will be downloaded and installed by PyCharm. A progress bar will appear while the installation is being done. Matplotlib should to appear in the list of installed packages for your Python interpreter once the installation is finished.

Screenshot-2023-10-26-232527

Step 6: Writing the Python Script

Create or open a Python script that contains your Matplotlib code to plot the graph. An example of a Python script for graphing is shown below.

Example 1: Plotting a Pie-Chart using Matplotlib

In this example, a pie chart is created using Matplotlib to visualize the distribution of car sales data. The dataset includes car brands such as Audi, BMW, Ford, Dodge, Porsche, and Mercedes, with corresponding sales figures displayed as a pie chart.

How to Install Matplotlib on PyCharm?

Problem Formulation: Given a PyCharm project. How to install the Matplotlib library in your project within a virtual environment or globally?

Here’s a solution that always works:

  • Open File > Settings > Project from the PyCharm menu.
  • Select your current project.
  • Click the Python Interpreter tab within your project tab.
  • Click the small + symbol to add a new library to the project.
  • Now type in the library to be installed, in your example «matplotlib» without quotes, and click Install Package .
  • Wait for the installation to terminate and close all popup windows.

Here’s the installation process as a short animated video—it works analogously for Matplotlib, just type in “matplotlib” in the search field instead:

Make sure to select only “matplotlib” because there are many other packages that are not required but also contain the term “matplotlib” (False positives):

install matplotlib pycharm

Alternatively, you can run the pip install matplotlib command in your PyCharm “Terminal” view:

$ pip install matplotlib

pip install matplotlib on PyCharm

Feel free to check out the following free email academy with Python cheat sheets to boost your coding skills!

To become a PyCharm master, check out our full course on the Finxter Computer Science Academy available for free for all Finxter Premium Members:

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.

To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.

His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.

Categories Dependency Management, Matplotlib, PyCharm, Python

Be on the Right Side of Change ��

  • The world is changing exponentially. Disruptive technologies such as AI, crypto, and automation eliminate entire industries. ��
  • Do you feel uncertain and afraid of being replaced by machines, leaving you without money, purpose, or value? Fear not! There a way to not merely survive but thrive in this new world!
  • Finxter is here to help you stay ahead of the curve, so you can keep winning as paradigms shift.

Learning Resources ��‍��

⭐ Boost your skills. Join our free email academy with daily emails teaching exponential with 1000+ tutorials on AI, data science, Python, freelancing, and Blockchain development!

Join the Finxter Academy and unlock access to premium courses �� to certify your skills in exponential technologies and programming.

New Finxter Tutorials:

  • Leverage Plays — Growing $10k to $472k using 50% Margin Loans to Buy a 30% CAGR Asset
  • Startup to Millionaire in 48 Months: A Dual Strategy of Business Growth and Smart Investing
  • Valuing $NVIDIA as a Real Estate Company That Sells Housing to AI Agents ($100k/Share in 2034)
  • Sо уӧυ’гё sтϊll υsᎥng r̸e̴g͟e̸x̷ to parse H̶T̷M̵L
  • How to Calculate CAGR in Google Sheets
  • How I Missed a 200x Gain in Nvidia Stock as a PhD in AI
  • [Fixed] Error Code 429: Quota Exceeded
  • What is Hugging Face Used For? Exploring its Applications in Machine Learning
  • Bitcoin Trading Simulation (Free Online Game)
  • Creating a Live Bitcoin Price Chart Using Binance API (No API Key!)

Finxter Categories:

Configure a system interpreter

To work with your Python code in PyCharm, you need to configure at least one interpreter. A system interpreter is the one that comes with your Python installation. You can use it solely for all Python scripts or take it as a base interpreter for Python virtual environments.

Configure a system interpreter

  1. Ensure that you have downloaded and installed Python on your computer. Installing Python on Windows from Microsoft Store If you are on Windows, you can download Python from the Microsoft Store and install it as a Python interpreter. Once the Python application is downloaded from the Microsoft Store, it becomes available in the list of the Python executables. Note that interpreters added from the Microsoft Store installations come with some limitations. Because of restrictions on Microsoft Store apps, Python scripts may not have full write access to shared locations such as TEMP and the registry.
  2. Do one of the following:
    • Click the Python Interpreter selector and choose Add New Interpreter .
    • Press Ctrl+Alt+S to open Settings and go to Project: | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.
    • Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.
  3. Select Add Local Interpreter .
  4. In the left-hand pane of the Add Python Interpreter dialog, select System Interpreter . Adding a system interpreter
  5. In the Interpreter drop-down, select one of the Python interpreters that have been installed in your system, or click and in the Select Python Interpreter dialog that opens, choose the desired Python executable. Selecting the Python executableYou will need admin privileges to install, remove, and upgrade packages for the system interpreter. When attempting to install an interpreter package through an intention action, you might receive the following error message: System Interpreter warning messageAs prompted, consider using a virtual environment for your project.
  6. Click OK to complete the task.

For any of the configured Python interpreters (but Docker-based), you can:

  • Manage interpreter paths
  • Install, uninstall, and upgrade packages

Last modified: 11 February 2024

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *