python - PyINIT 没有被调用
问题描述
在 Visual Studio 2019 中,尝试运行本教程 https://docs.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio?view=vs-2019 除外我称我的模块为 twitc。
初始化模块的代码永远不会被调用。
import twitc
工作正常。
但是当我尝试调用 twitc.generate_twit_list(0.1) 它说
module 'twitc' has no attribute 'generate_twit_list'
我的代码喜欢
#include <Python.h>
#include <Windows.h>
#include <cmath>
const double e = 2.7182818284590452353602874713527;
double sinh_impl(double x) {
return (1 - pow(e, (-2 * x))) / (2 * pow(e, -x));
}
double cosh_impl(double x) {
return (1 + pow(e, (-2 * x))) / (2 * pow(e, -x));
}
PyObject* generate_twit_list_impl(PyObject*, PyObject* o) {
double x = PyFloat_AsDouble(o);
double tanh_x = sinh_impl(x) / cosh_impl(x);
return PyFloat_FromDouble(tanh_x);
}
static PyMethodDef twitc_methods[] = {
{ "generate_twit_list", (PyCFunction)generate_twit_list_impl, METH_VARARGS, "Generate the twit list of inter tensor links as a cache." },
{ nullptr, nullptr, 0, nullptr }
};
static PyModuleDef twitc_module = {
PyModuleDef_HEAD_INIT,
"twitc",
"Provides some functions, but faster",
0,
twitc_methods
};
PyMODINIT_FUNC PyInit_twitc() {
printf("Init TWITC\n"); // THIS NEVER GETS CALLED
return PyModule_Create(&twitc_module);
}
任何想法为什么这会失败?
解决方案
已解决 - 我没有在 python37.lib 中链接现在它可以工作了。
推荐阅读
- jquery - 如何根据从 ajax 调用返回的数据动态地将选项添加到我的自动完成功能?
- ubuntu - GCE 实例崩溃后如何自动重启?
- javascript - 为什么 xmlHttpRequest.Open 仅在我输入字符串时才起作用?
- angularjs - AngularJS - 将 url 动态添加到 $sceDelegateProvider.resourceUrlWhitelist
- javascript - 原型返回我的函数而不是返回值
- css - 是否可以将重复样式放在 .less 组件中
- ansible - MQ 用户在 ansible 安装期间创建成功,但在安装后消失
- java - 为什么最后的美元变化计算错误
- r - 通过 shell 使用 R 时出现问题 - 但相同的脚本在 RStudio 中有效
- tensorflow2.0 - 使用占位符从 MultivariateNormalDiag 采样