Boost.Python.ArgumentError: Python argument types in rdkit.Chem.rdMolDescriptors.GetMorganFingerprintAsBitVect(NoneType, int)
时间: 2024-05-24 15:10:48 浏览: 379
This error message indicates that there is a problem with the input arguments to the GetMorganFingerprintAsBitVect function from the RDKit module. Specifically, the first argument (the molecule object) is of type NoneType, which means that it is not a valid molecule object. The second argument (the radius of the fingerprint) is an integer, which is the correct type.
To fix this error, you need to make sure that the first argument is a valid molecule object. Check that the molecule object is being properly initialized or loaded before passing it to the function. If the molecule object is still NoneType after initialization or loading, then there may be an issue with the file or data source.
相关问题
Boost.Python.ArgumentError: Python argument types in
这个错误通常是因为您在Python中向C++函数传递了不正确的参数类型。Boost.Python要求您明确指定C++函数的参数类型,以便正确地将Python对象转换为C++对象。如果您传递了不正确的参数类型,Boost.Python将会抛出一个ArgumentError异常。
您可以检查一下您的Python代码,确保您传递给C++函数的所有参数都是正确的类型。另外,您也可以检查一下C++函数的声明和定义,确保它们与Python代码中使用的参数类型相匹配。如果您使用了Boost.Python提供的类型转换器,可以尝试打印一些调试信息,以便更好地了解对象转换的过程。
Boost.Python.ArgumentError: Python argument types in错误解决
`Boost.Python.ArgumentError: Python argument types in` 错误通常出现在使用 C++ 和 Python 的结合库 Boost.Python 进行跨语言调用时。它表示传递给某个函数的参数类型不符合预期。
### 解决步骤
1. **检查函数签名**
确保从 Python 调用 C++ 函数时,所传入的参数数量和类型都匹配 C++ 中定义的函数签名。如果 C++ 函数需要特定类型的参数,则 Python 应提供兼容的数据结构。
2. **数据转换问题**
如果涉及到复杂的数据类型(例如自定义类、容器等),确保已在 Boost.Python 中正确注册了这些类型,并实现了必要的隐式或显式的类型转换机制。
3. **调试信息分析**
查看完整的错误堆栈信息,定位具体出错的位置以及涉及哪些参数导致了不匹配的情况。
4. **示例代码验证**
创建简单的测试用例重现该问题并逐步排查是否因为某些特殊的输入引起异常。
5. **文档参考**
参考官方 [Boost.Python](https://www.boost.org/doc/libs/release/libs/python/) 文档了解关于如何处理常见错误及最佳实践建议的信息资源链接。
---
#### 示例修正流程:
假设我们有这样一个场景,在 C++ 文件中有如下导出方法:
```cpp
void print_int(int x){
std::cout << "Integer value is:" << x;
}
BOOST_PYTHON_MODULE(mymodule)
{
def("print_int", &print_int);
}
```
而你在 python端如此尝试调用了却报错了上述提到的那个Argument Error :
```python
import mymodule as mp
mp.print_int('abc') #这里应该是一个整数而不是字符串字符序列形式
```
正确的做法应该是将 'abc' 改成真正的integer型数值比如 `789`, 即改为下面这样才不会触发argument mismatch error.
```python
mp.print_int(789)
```
阅读全文
相关推荐

















