首页 > 解决方案 > 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!

标签: pythonmatplotlibvisual-studio-codepipconda

解决方案


修复,重新安装Anaconda,然后新建一个环境,然后用pip强制安装:

pip install --upgrade --force-install matplotlib

numpy 和 matplotlib 现在工作得很好:)


推荐阅读