Python不会导入我的模块

时间:2017-07-10 14:41:26

标签: python module shared-libraries ctypes

我使用ctypes包装了一个库,但是库变得越来越广泛了,我想把它变成一个模块,所以我可以输入     导入my_moule 进入python控制台。我已将文件保存在以下位置:C:\ Users \ name.ipython \ extensions \ my_module.py但是当我尝试将其导入python控制台时,我得到“ModuleNotFoundError:没有名为'my_module'的模块”

在发布此问题之前搜索答案时,我注意到大多数模块都有类似的东西:

class Name(Type):

def __init__(self):

我是否需要进一步定义我的结构?

我的问题是:我将模块保存到正确的位置吗?

我的模块的缩短版本看起来像这样,我有大约10个结构,它们更长。:

import ctypes 
from ctypes import *

MF = (b'path_to_file')   

# Wrapping the library 
class TTag(Structure):
_fields_ = [
         ('SecondsMillie', ctypes.c_ulong),
         ('SecondsMicro', ctypes.c_ushort)]
class Event(Structure):
_fields_ = [
         ('count', ctypes.c_int),
         ('name', ctypes.c_char_p)]
class Header(Structure):
_fields_ = [
         ('fileSig', ctypes.c_ulong),
         ('refTime[6]', ctypes.c_ulong * 6)]

1 个答案:

答案 0 :(得分:0)

使用我创建的模块时,我会将单独的模块文件保存到我的程序目录或其子目录中。

我使用Visual Studio 2017;所以YMMV,我在Visual Studio中向我的解决方案添加了一个新文件,Visual Studio自动将该文件存储在解决方案(程序)目录的子目录中。

相关问题