简体   繁体   中英

import matplotlib & Visual Studio Code

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!

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

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 :)

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