Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
120 views
in Technique[技术] by (71.8m points)

windows - NSIS after PyInstaller Kivy app can't find database

I successfully packaged my Kivy app for Windows using PyInstaller and my app.exe runs without any problems. (.spec: Kivy 1.9.1 Windows package .spec single exe)

For easier distribution I want to package my file to a single standalone .exe. My .nsi file:

SilentInstall silent
Section
InitPluginsDir
Setoutpath KanjiOrigin
File /r "distKanjiOrigin*"
ExecWait "distKanjiOriginKanjiOrigin.exe"
Setoutpath $TEMP
SectionEnd

A .exe is build without error: http://pastebin.com/h91jzGgY

However when running this .exe made by NSIS, the app runs until I need to connect to my internal database at datadbKanji-story.db, which is not found. (When opening the .exe, it is in there, so the database has been included).

sqlite3.OperationalError: unable to open database: datadbKanji-story.db

When I extract my .exe with 7zip and try to run the KanjiOrigin.exe from PyInstaller, I get the following error: D:pathKanjiOriginKanjiOrigin.exe is not a valid Win32 application. (Not sure if this is relevant).

Edit 2

I don't know what changed, but when opening the NSIS .exe with 7zip now, it doesn't give an error extracting the PyInstaller .exe anymore. However when trying to run the extracted PyInstaller .exe, I get the following error:

PyInstaller Bootloader 3.x
LOADER: executable is D:pathKanjiOriginKanjiOrigin.exe
LOADER: homepath is D:pathKanjiOrigin
LOADER: _MEIPASS2 is NULL
LOADER: archivename is D:pathKanjiOriginKanjiOrigin.exe
LOADER: pyi_arch_check_cookie failed
LOADER: archivename is D:pathKanjiOriginKanjiOrigin.pkg
LOADER: Cannot open archive: D:pathKanjiOriginKanjiOrigin.pkg
Cannot open self D:pathKanjiOriginKanjiOrigin.exe or archive D:pathKanjiOriginKanjiOrigin.pkg

Also the included database doesn't seem to be corrupted, because after extraction I can successfully open it with sqlitebrowser (http://sqlitebrowser.org/).

What do I do wrong? Is it Setoutpath $TEMP?

Edit:

If I manually include the database with the same folder structure (datadbKanji-story.db) outside the NSIS created .exe, it can find the database? Why can it find an external database, but not the internal one included in the NSIS .exe?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It looks like you just copied some code from somewhere without understanding it.

SilentInstall silent
Section
InitPluginsDir
SetOutPath $Pluginsdir ; This must be a full path
File myapp.exe
ExecWait '"$pluginsdirmyapp.exe"' ; This should be a full path as well.
SetOutPath $TEMP
SectionEnd

is typical for code that temporarily extracts a .exe and then executes it from the %Temp% folder but you would not do this in a installer, only if you are creating a portable application wrapper.

Another issue in you code is that you are just using relative paths. From the documentation for SetOutPath:

Must be a full pathname, usually is just $INSTDIR

And as for what SetOutPath $TEMP does; SetOutPath internally sets the current directory for the process and the current directory cannot be deleted while the application is running so setting it to $TEMP at the end is just a workaround that only needs to be used if you used SetOutPath $PluginsDir because you want NSIS to be able to delete $PluginsDir before it quits.

If you are using NSIS to write a portable application wrapper then you should just make sure you are using full paths and then it should work. On the other hand, if you are writing a normal installer then you should not be dealing with $PluginsDir, you should use SetOutPath $InstDir and the InstallDir attribute should be set to something like "$ProgramFilesMyApp"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...