ctypes

python3.8安装flask出现错误“ModuleNotFoundError: No module named '_ctypes'”

有些话、适合烂在心里 提交于 2021-02-15 16:56:54
本想在CentOS下配置flask+nginx+uwsgi环境,结果安装最基础的flask包都出了问题...以下是我的环境: 服务器:阿里云ECS CentOS7 python版本:3.8.0 问题描述: 执行命令“ pip3 install flask ”安装flask时,出现如下错误: from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named ' _ctypes' 从错误描述来看是缺少_ctypes模块,根据网上搜索结果,这个错误大多数发生在安装python3.7及以上版本时出现,解决方法如下: 安装python时出此错的解决方法: 原因是缺少包“libffi-devel”,利用yum安装便可 yum install libffi-devel ——参考“ 海棠未满 ” 然而对于我来说,问题并没有解决,我在安装libffi-devel后再次执行pip安装命令仍报同样错误,但大多数人都可以通过上述方法完美解决,这不由得引起我的思考 思考: 我与上述解决方案的不同点在于——我在安装python3.8时并未出现错误,而是在拥有python3.8后,安装flask时出现该错误 受 Bryan 启发,其在安装“libffi-devel”后重新安装了python,解决了问题

from: cant read /varmail/ctypes when called

心已入冬 提交于 2021-02-11 15:45:19
问题 I am trying to implement some object detection in a project of mine using darknet.py. from my terminal I am able to run python3 darknet.py and get my results all fine. But when I have tried to include it in my own program I am getting several errors; from: cant read /var/mail/ctypes import im6.q16: not authorized math @error/constitute.c/writeimage/1037 I am not sure how to proceed. I have made sure darknet.py starts with #!/usr/bin/ env python3 as does my program, i am trying to run it with

from: cant read /varmail/ctypes when called

心已入冬 提交于 2021-02-11 15:44:28
问题 I am trying to implement some object detection in a project of mine using darknet.py. from my terminal I am able to run python3 darknet.py and get my results all fine. But when I have tried to include it in my own program I am getting several errors; from: cant read /var/mail/ctypes import im6.q16: not authorized math @error/constitute.c/writeimage/1037 I am not sure how to proceed. I have made sure darknet.py starts with #!/usr/bin/ env python3 as does my program, i am trying to run it with

Can I pass a Python “self” object to a C function as c_void_p and cast to original type for use in a callback?

爷,独闯天下 提交于 2021-02-11 06:16:41
问题 Using ctypes to interface my python3 code with a C API. One of the C functions registers a callback function– i.e. it takes a function pointer to the callback and a void* userdata to be made available in that callback. // typedef and C function in myClibrary.so typedef void(__cdecl *callback_function_type)(void*); int RegCallback(callback_function_type callback_function, void* userbdata); I have successfully defined the required callback function type in python using CFUNCTYPE() , passed an

Can I pass a Python “self” object to a C function as c_void_p and cast to original type for use in a callback?

☆樱花仙子☆ 提交于 2021-02-11 06:14:53
问题 Using ctypes to interface my python3 code with a C API. One of the C functions registers a callback function– i.e. it takes a function pointer to the callback and a void* userdata to be made available in that callback. // typedef and C function in myClibrary.so typedef void(__cdecl *callback_function_type)(void*); int RegCallback(callback_function_type callback_function, void* userbdata); I have successfully defined the required callback function type in python using CFUNCTYPE() , passed an

How to pass ctypes.POINTER to boost.python

最后都变了- 提交于 2021-02-10 20:31:11
问题 I have following code: old_lib.h: struct DUMMY { // some members }; module.cpp: #include <boost/python.hpp> #include "old_lib.h" namespace py = boost::python; void foo(py::object const& p) { // How to get rid of ctypes.addressof()? static py::object ctypes_addressof = py::import("ctypes").attr("addressof"); DUMMY *ptr = *reinterpret_cast<DUMMY**>(uintptr_t(py::extract<uintptr_t>(ctypes_addressof(p)))); } BOOST_PYTHON_MODULE(module) { py::def("foo", &foo, args("p")); } old_python.py: import

C++ & Python: Pass and return a 2D double pointer array from python to c++

℡╲_俬逩灬. 提交于 2021-02-10 14:17:21
问题 I want to pass a 2D array from Python to a C++ function and then return an array of the same type, same dimensions, to Python. I am aware this question has already been asked several times, but I haven't been able to find a relevant answer to my question. For my problem, I must use a double pointer array and have the function returning a double pointer array (not void as many examples show). My C++ function is: #include <stdio.h> #include <stdlib.h> extern "C" double** dot(double **a, int m,

Why the irrelevant code made a difference?

送分小仙女□ 提交于 2021-02-08 13:59:14
问题 I am thinking to make a progress bar with python in terminal. First, I have to get the width(columns) of terminal window. In python 2.7, there is no standard library can do this on Windows. I know maybe I have to call Windows Console API manually. According to MSDN and Python Documentation, I wrote the following code: import ctypes import ctypes.wintypes class CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure): _fields_ = [ ('dwSize', ctypes.wintypes._COORD), ('dwCursorPosition', ctypes.wintypes.

How to return char ** from C++ and fill it in a list in Python using ctypes?

柔情痞子 提交于 2021-02-08 08:47:17
问题 I've been trying to return an array of strings from C++ to python a follows: // c++ code extern "C" char** queryTree(char* treename, float rad, int kn, char*name, char *hash){ //.... bunch of other manipulation using parameters... int nbr = 3; // number of string I wish to pass char **queryResult = (char **) malloc(nbr* sizeof(char**)); for (int j=0;j<nbr;j++){ queryResult[j] = (char *) malloc(strlen(results[j]->id)+1); if(queryResult[j]){ strcpy(queryResult[j], "Hello"); // just a sample

Pass python list to C/C++ as 'float*' or 'int*'

亡梦爱人 提交于 2021-02-08 06:57:53
问题 C/C++ void func(float* xyz1, float* xyz2,int n){ //do something for(int i=0; i<n;i++){ printf("%f %f\n",xyz1[i],xyz2[i]); } } Python import numpy as np n = 1000000 xyz1 = np.random.random((n,)).tolist() xyz2 = np.random.random((n,)).tolist() #pass above array to the C/C++ code for further processing. func(xyz1,xyz2,n) # <-- the call to the c/c++ code I have seen examples that call the C++ code using more high-level data structures like C++'s array . However, I simply want to pass it using