1

I'm using Visual Studio Code and want to be able to use numpy and matplotlib. The code I have is simply:

import numpy
import matplotlib.pyplot as plt

The first line works fine, but the second line returns this error:

Traceback (most recent call last):
  File "c:\Users\(username)\OneDrive\College\Code\Python\test.py", line 2, in <module>
    import matplotlib.pyplot as plt
  File "C:\Users\(username)\anaconda3\lib\site-packages\matplotlib\__init__.py", line 205, in <module>
    _check_versions()
  File "C:\Users\(username)\anaconda3\lib\site-packages\matplotlib\__init__.py", line 190, in _check_versions
    from . import ft2font
ImportError: DLL load failed: The specified module could not be found.

However, I do know that I have matplotlib installed on Anaconda, as trying to install it using pip tells me that Requirement already satisfied.

I'm using Visual Studio Code with Python 3.7.6 on 64-bit Windows with Anaconda.

Any help would be greatly appreciated. Thank you!

5
  • 1
    Are you certain that VSCode is using the correct Conda environment? As an aside, why use pip to install matplotlib? Commented Sep 23, 2020 at 19:00
  • I am certain that VSCode is using the correct Conda environment (at the bottom left, it says "Python 3.7.6 64-bit ('base': conda). Commented Sep 23, 2020 at 21:05
  • You should use a new environment for each project/application, using the base environment for everything will lead to things breaking, doubly so if you're using pip. You should consider removing and installing Conda again. Commented Sep 23, 2020 at 21:21
  • Ok, I've removed and installed Conda again, and set up a new environment per the instructions at docs.conda.io/projects/conda/en/latest/user-guide/tasks/… However, in Visual Studio Code the environment is not being detected for some reason (when I select python interpreter, it only has the base as an option). I'm not sure where to go from here. How do I get Visual Studio Code to detect the new environment? Also tbh I've used pip because I forgot conda can do the exact same thing, but in both cases the requirement is already satisfied. Commented Sep 23, 2020 at 22:29
  • Fixed, see answer below. Thanks for all your help! Commented Sep 23, 2020 at 23:32

2 Answers 2

1

Fixed, reinstalled Anaconda, then created a new environment, then used pip to force-install:

pip install --upgrade --force-install matplotlib

numpy and matplotlib now work perfectly fine :)

Sign up to request clarification or add additional context in comments.

1 Comment

the switch should be --force-reinstall
0

Your IDE (Visual Studio Code) is using some environment to run python: it can be anaconda, and it can be something different. The fact that you installed it on anaconda may not be enough, as you need to make sure the visual studio is needed running anaconda environment.

See the following guide: How to create and manage Python environments in Visual Studio

1 Comment

Per above comment, I am certain that VSCode is using the correct Conda environment (at the bottom left, it says "Python 3.7.6 64-bit ('base': conda).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.