请帮助解决以下问题。
我试图在Juypter笔记本电脑的一个单元格中运行以下代码:
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
plt.style.use(['science', 'notebook'])
import sympy as smp
from skimage import color
from skimage import io
from scipy.fft import fftfreq
from scipy.fft import fft, ifft, fft2, ifft2
字符串
但收到以下错误消息:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File ~\anaconda3\lib\site-packages\matplotlib\style\core.py:166, in use(style)
165 try:
--> 166 style = _rc_params_in_file(style)
167 except IOError as err:
File ~\anaconda3\lib\site-packages\matplotlib\__init__.py:850, in _rc_params_in_file(fname, transform, fail_on_error)
849 rc_temp = {}
--> 850 with _open_file_or_url(fname) as fd:
851 try:
File ~\anaconda3\lib\contextlib.py:135, in _GeneratorContextManager.__enter__(self)
134 try:
--> 135 return next(self.gen)
136 except StopIteration:
File ~\anaconda3\lib\site-packages\matplotlib\__init__.py:827, in _open_file_or_url(fname)
826 fname = os.path.expanduser(fname)
--> 827 with open(fname, encoding='utf-8') as f:
828 yield f
FileNotFoundError: [Errno 2] No such file or directory: 'science'
The above exception was the direct cause of the following exception:
OSError Traceback (most recent call last)
Cell In[1], line 4
2 import scipy as sp
3 import matplotlib.pyplot as plt
----> 4 plt.style.use(['science', 'notebook'])
5 import sympy as smp
6 from skimage import color
File ~\anaconda3\lib\site-packages\matplotlib\style\core.py:168, in use(style)
166 style = _rc_params_in_file(style)
167 except IOError as err:
--> 168 raise IOError(
169 f"{style!r} is not a valid package style, path of style "
170 f"file, URL of style file, or library style name (library "
171 f"styles are listed in `style.available`)") from err
172 filtered = {}
173 for k in style: # don't trigger RcParams.__getitem__('backend')
OSError: 'science' is not a valid package style, path of style file, URL of style file, or library style name (library styles are listed in `style.available`)
型
我曾经运行代码,并期待没有错误信息。但它似乎是错误提示后,我运行以下代码在Juypter笔记本的一个单元格:
%pip install opencv-python
型
我使用的是Python 3.10。
1条答案
按热度按时间ryevplcw1#
情况似乎是
plt.style.use(['science', 'notebook'])
是一个错误的代码片段。要调试此错误,请执行以下操作:
字符串
这将返回以下内容:
型
您可能正在尝试使用不在可用软件包列表中的软件包。请参见以下使用正确参考Example code used below source的示例:
型
希望能帮上忙