[英]Include python files within subdirectory with cxfreeze
我正在嘗試將python項目凍結為exe。 當我在目錄“ Notifier”中打開命令提示符並運行cxfreeze notifier/main.py
,項目將正確編譯。 我試圖從setup.py中獲得相同的結果,以便當我運行python setup.py build_exe
,像以前一樣創建一個具有依賴項的exe。
這是目錄結構:
Notifier/
|notifier/
|- __init__.py
|- main.py
|- sender.py
|- request.py
|setup.py
當我運行python setup.py build_exe
,我注意到在Missing Modules:
它具有sender imported from main__main__
。 當我從Notifier/build/exe.win32-2.7
運行main.exe時,發生以下錯誤。
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "notifier/main.py", line 1, in <module>
ImportError: No module named sender
這是我的setup.py:
from cx_Freeze import setup, Executable
import requests.certs
options = {
'build_exe': {
'include_files': [(requests.certs.where(), 'cacert.pem')]
}
}
setup(
name='Notifier',
version='0.1',
license='MIT',
author='David Corbin',
#install_requires=['requests', 'websocket', 'cx_Freeze'],
options=options,
executables=[Executable("groupmenotifier/main.py")]
)
您需要在notifier
文件夾中名為__init__.py
的文件。
我必須將groupmenotifier/
目錄添加到搜索路徑,以便cxfreeze可以找到並使用它。
sys.path.append(os.getcwd()+"\\groupmenotifier")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.