Running 'build_ext --inplace' D:\Anaconda\envs\gprMax\lib\site-packages\setuptools\dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ********************************************************************************
时间: 2025-05-20 22:10:56 浏览: 200
### 解决 SetuptoolsDeprecationWarning 警告问题
`SetuptoolsDeprecationWarning` 是由于 setuptools 的某些功能被弃用而引发的警告。具体到 `License classifiers are deprecated` 这一情况,是因为 PyPI 已经不再推荐使用许可证分类器来指定项目的许可信息[^5]。
#### 替代方案
为了消除这一警告,可以采取以下措施:
1. **移除 `classifiers` 中的许可证字段**
如果项目配置文件(通常是 `setup.py` 或 `pyproject.toml`)中有类似于以下的内容:
```python
classifiers=[
...
'License :: OSI Approved :: MIT License',
...
]
```
可以删除这些与许可证相关的条目,并改用其他方式声明许可证信息。
2. **在 `setup.cfg` 或 `pyproject.toml` 中定义许可证**
推荐的方式是在 `setup.cfg` 文件中添加如下内容:
```ini
[metadata]
license_files = LICENSE.txt
```
或者如果使用的是 `pyproject.toml`,则可以写成:
```toml
[tool.setuptools]
license-files = ["LICENSE.txt"]
```
3. **确保许可证文件存在**
确保项目根目录下有一个名为 `LICENSE` 或 `LICENSE.txt` 的文件,其中包含项目的许可证文本。PyPI 会在打包时自动读取该文件作为许可证信息的一部分。
4. **更新 setuptools 版本**
使用较新的 setuptools 版本可能有助于减少不必要的警告。可以通过以下命令升级 setuptools:
```bash
pip install --upgrade setuptools
```
#### 配置 gprMax 环境中的 build_ext 和 anaconda 支持
对于涉及 `build_ext --inplace` 的场景,在 Anaconda 环境中构建扩展模块时需要注意以下几点:
- 安装必要的编译工具链:Anaconda 默认不提供完整的 C/C++ 编译器支持。可以在 Conda 环境中通过以下命令安装 MinGW-W64 工具链(适用于 Windows 平台):
```bash
conda install mingw libpython
```
- 修改 `setup.py` 文件以兼容 Anaconda 构建流程。通常情况下,需要调整 `Extension` 类型对象的参数,例如设置合适的头文件路径和库路径。
- 执行构建操作前,确认已激活目标 Conda 环境:
```bash
conda activate your_env_name
python setup.py build_ext --inplace
```
---
### 示例代码片段
以下是针对上述修改的一个简单示例:
```python
from setuptools import setup, Extension
module = Extension(
'example_module',
sources=['example.c'],
)
setup(
name='Example Module',
version='0.1',
description='A simple example module.',
ext_modules=[module],
options={'build': {'build_lib': './'}},
)
```
执行以下命令即可完成本地构建:
```bash
python setup.py build_ext --inplace
```
---
###
阅读全文
相关推荐



















