/opt/anaconda3/envs/pst/lib/python3.7/site-packages/pytorch_lightning/trainer/connectors/accelerator_connector.py:479: LightningDeprecationWarning: Setting `Trainer(gpus=1)` is deprecated in v1.7 and will be removed in v2.0. Please use `Trainer(accelerator='gpu', devices=1)` instead. f"Setting `Trainer(gpus={gpus!r})` is deprecated in v1.7 and will be removed"
时间: 2024-01-22 17:01:57 浏览: 235
这是一个来自 PyTorch Lightning 的警告信息,它告诉你在版本1.7中设置 `Trainer(gpus=1)` 已经被弃用,将在版本2.0中被移除,请使用 `Trainer(accelerator='gpu', devices=1)` 替代。这是因为在 PyTorch Lightning 1.7 中引入了加速器(accelerator)的概念,用于支持不同的硬件加速器(如GPU、TPU等),而 `gpus` 参数不再适用于所有硬件加速器。
相关问题
>>> import torchvision Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/torchvision/__init__.py", line 7, in <module> from torchvision import datasets File "/opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/torchvision/datasets/__init__.py", line 1, in <module> from .lsun import LSUN, LSUNClass File "/opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/torchvision/datasets/lsun.py", line 2, in <module> from PIL import Image File "/opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/PIL/Image.py", line 100, in <module> from . import _imaging as core ImportError: dlopen(/opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so, 2): Library not loaded: @rpath/libjpeg.9.dylib Referenced from: /opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so Reason: Incompatible library version: _imaging.cpython-39-darwin.so requires version 15.0.0 or later, but libjpeg.9.dylib provides version 12.0.0
这个错误提示显示 PIL 库中的 _imaging.cpython-39-darwin.so 动态链接库依赖的 libjpeg.9.dylib 版本不兼容,需要版本号为 15.0.0 或更高版本。
解决方法:
1.卸载已安装的 Pillow 库,执行以下命令:
```
pip uninstall pillow
```
2. 安装 libjpeg-turbo,执行以下命令:
```
brew install libjpeg-turbo
```
3. 安装 Pillow 库,并指定使用 libjpeg-turbo 库,执行以下命令:
```
pip install --no-cache-dir -I pillow-SO_LATEST_VERSION --global-option="build_ext" --global-option="--disable-jpeg" --global-option="--enable-jpeg2000" --global-option="--enable-zlib" --global-option="--enable-turbojpeg"
```
其中,SO_LATEST_VERSION 是指最新版本的 Pillow 库的版本号。您可以在 PyPI 上查看最新版本的 Pillow 库的版本号。
4. 验证 Pillow 库是否安装成功,执行以下命令:
```
python -c "from PIL import Image; print(Image.core.jpeglib_version)"
```
如果输出的版本号为 libjpeg-turbo 的版本号,则说明安装成功。
/Users/zhengyaqi/opt/anaconda3/envs/py/bin/python /Users/zhengyaqi/PycharmProjects/pythonProject13/main.py Traceback (most recent call last): File "/Users/zhengyaqi/PycharmProjects/pythonProject13/main.py", line 32, in <module> find_and_copy_files(source_folder, target_folder, excel_file) File "/Users/zhengyaqi/PycharmProjects/pythonProject13/main.py", line 7, in find_and_copy_files excel_data = pd.read_excel(excel_file, engine='xlrd') File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 478, in read_excel io = ExcelFile(io, storage_options=storage_options, engine=engine) File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 1513, in __init__ self._reader = self._engines[engine](self._io, storage_options=storage_options) File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/pandas/io/excel/_xlrd.py", line 35, in __init__ super().__init__(filepath_or_buffer, storage_options=storage_options) File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 540, in __init__ self.book = self.load_workbook(self.handles.handle) File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/pandas/io/excel/_xlrd.py", line 48, in load_workbook return open_workbook(file_contents=data) File "/Users/zhengyaqi/opt/anaconda3/envs/py/lib/python3.10/site-packages/xlrd/__init__.py", line 170, in open_workbook raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported') xlrd.biffh.XLRDError: Excel xlsx file; not supported报错结果
这个错误是由于 `xlrd` 引擎不支持读取 Excel `.xlsx` 文件引起的。`xlrd` 只支持旧版本的 Excel `.xls` 文件。
为了解决这个问题,你可以尝试使用 `openpyxl` 引擎来读取 `.xlsx` 文件。可以将代码中的 `engine='xlrd'` 修改为 `engine='openpyxl'`,如下所示:
```python
excel_data = pd.read_excel(excel_file, engine='openpyxl')
```
然后重新运行代码,看看是否能够成功读取 Excel 文件。
如果你还没有安装 `openpyxl`,可以在终端中使用以下命令进行安装:
```
pip install openpyxl
```
如果仍然遇到问题,请确保你的 Excel 文件没有损坏,并且使用的是支持的文件格式。
希望这次能够解决你的问题,如果还有其他疑问,请随时向我提问!
阅读全文