且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

已安装的 Python 脚本无法导入包模块

更新时间:2023-09-13 08:21:10

首先,当您安装软件包时,您正在导入核心,而没有确定它是 multitool 软件包的一部分.所以:

First off, when you install the package you are importing core without identifying it is being apart of the multitool package. So:

import core

应该是,

from multitool import core

这样解释器就知道要从中导入核心的模块.

That way the interpreter knows the module to import core from.

至于安装包的目录结构,脚本需要进入与模块本身不同的目录.显示的目录结构方式 Distutils 会将您命名的脚本安装到您​​的系统查找可执行文件的位置以及包本身中,这可能是所有混淆的来源.

As for the directory structure of the installed package, scripts need to go into a separate directory from the module itself. The way the shown directory structure is Distutils will install the script you named into both a place your system looks for executables as well as in the package itself, which is likely where all the confusion is coming from.