简体   繁体   中英

Unable to import 'matplotlib.pyplot' without conda

I understand that a very similar question has been asked before, but the answer to said question was given in the context of anaconda, which did not help me as I am not familiar with anaconda. Anyhow:

I'm trying to get started with tensorflow in visual studio code, but when I try to type the following:

import matplotlib.pyplot as plt

I get this error: Unable to import 'matplotlib.pyplot' (along with pylint(import-error) in grayed-out text).

How do I resolve this error without using anaconda? If the answer relates to typing something into a terminal, please specify where the command is supposed to be typed in, as part of why I can't figure this out is because online solutions never specify where a command should go. Thanks!

I recommend getting familiar with the basic concepts of Python first. From the different versions (Python 2.7, Python 3.x), the structure (libraries), and good practices (use virtual environments to sandbox your structure).

  • Why and how to create virtual environments, you may want to read this or this .
  • libraries are just as in any other language toolboxes with functions and data-structures. You need to install them on your system (Tensorflow is one example, matplotlib another). Most libraries can be installed via the package manager pip (which may install Python2.7 or Python3.x libraries, depending on what you default Python is or in what virtual environment you are currently working).
  • be aware that different Python versions behave differently. Tensorflow is not available for all versions (not for Python2.7 in general but also not for all Python3.x versions).

Anyway, open up a command prompt (as you haven't specified your system, I assume windows. => open PowerShell or cmd).

pip3 install matplotlib

This installs the library matplotlib in the root environment. If you have an environment, activate it before issuing this command.

I strongly recommend reading an introduction to Python to get a better overview of the concept of Python.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM