使用pyinstaller把py文件打包成exe文件后,可以在没有安装python的电脑上运行py程序,真的很方便呢!
但是我不知道该如何导入自己写的module(sample_test),请帮忙看一下。
没有打包之前是可以正常运行的:
文件结构:
test1
├ TEMP
│ └ sample_test.py
└ callTest.py
callTest.py:
import sys
sys.path.append('./TEMP')
from sample_test import *
stdResult = eval("dispatch_character('input_test')")
print(stdResult)
sample_test.py:
def dispatch_character(argv):
return argv + '_ok'
运行【py callTest.py】输出结果:input_test_ok
使用pyinstaller生成exe文件之后找不到自己写的module(sample_test):
打包:
pyinstaller callTest.py --onefile
pyinstaller sample_test.py --onefile
文件结构:
test2
├ TEMP
│ └ sample_test.exe
└ callTest.exe
运行【callTest.exe】报错:
Traceback (most recent call last):
File "callTest.py", line 3, in <module>
ModuleNotFoundError: No module named 'sample_test'
[19324] Failed to execute script callTest
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
参考园子里的博文:Python打包方法——Pyinstaller