我在a.py
. 我a.py
用我的通用python 二进制文件运行。在里面a.py
,我有
import some_module
def simple_function():
...
def complex_function():
some_module.some_func()
现在,我想导入simple_function()
到b.py
,它必须与另一个 python(软件捆绑安装)一起运行,而这个 python 没有some_module
安装。
当我使用软件捆绑的 python运行b.py
(包含 line from a import simple_function
)时,我收到了这个错误,正如预期的那样。
ImportError: No module named 'some_module'
有办法解决吗?如您所见,simple_function()
不需要some_module
.
我能想到的一种解决方案是将 import 语句放在complex_function
.
def simple_function():
...
def complex_function():
import some_module
some_module.some_func()
但我确信 linters 和格式检查器会抱怨它。更好的解决方案?
解决方案是将复杂功能单独拆分为单独的模块。
当你在一个模块中导入一个函数时,你是在导入整个模块。
其他解决办法是some_module
在其他python安装中安装...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句