我创建了两个python文件,目录/文件关系如下:
mytest---
|---mycommon.py
|---myMainDir---
|----myMain.py
Run Code Online (Sandbox Code Playgroud)
在mycommon.py中:
def myFunc(a):
...
Run Code Online (Sandbox Code Playgroud)
在myMain.py中:
import sys
sys.path.append(os.path.join(os.path.dirname(os.path.abspath('__file__')), '..'))
import mycommon.py
mycommon.myFunc("abc")
Run Code Online (Sandbox Code Playgroud)
然后我使用pyinstaller创建了exe:
pyinstall.py -F mytest\myMainDir\myMain.py
Run Code Online (Sandbox Code Playgroud)
MyMain.exe已创建,但运行时会告诉无法找到mycommon模块.