You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a little unsure the best place to put this, as I'm using py2exe and nsis to freeze and install a project. I'm not to sure which side of the chain I should/can resolve this from.
I'm able to py2exe.freeze my project, and launch it via the created *.exe on my Windows machine. I'm also able to create an installer which install the application to Program Files, and creates a desktop shortcut, all from my development machine.
However, when I go to move that workflow over to a GitHub Action, when I install the application from there I get a ModuleNotFoundError for my applications namespace/module/package (unsure the technically correct term there).
For example, I have a project with the structure like:
And the errors are for the import of my package e.g. from myapp.utils import *.
To get around this I tried to programatically add the module/package to python sys.path using sys.path.append(os.path.dirname(__file__)) as a kind of hacky solution, but actually that ends up with an error saying __file__ doesn't exist, and if I meant to say __name__.
I'm unsure either the correct way to solve this, or a hack way to solve this at the moment; open to either.
The differences in the freezing are that when ive done it on a local development machine (that works), I've done this in a virtual environment. When I've py2exe.freeze in the GitHub action, that's been from the system install or python. Not really sure any other differences that would cause problems.
Ideally there's a way of fixing the this so the myapp module is appropriately added to the PYTHONPATH. But otherwise, if I need to hard code in a sys.path.append(<path>), I'm not sure where that path would be in a post-frozen project.
Would appreciate any pointers if anyone has experience with this. Thanks.
Here's the build script I use, if it helps give any more context:
# scripts/build.pyimportosimportshutilimporttomllibimportpathlibimportpy2exeNAME="My App"HERE=pathlib.Path(__file__)
ROOT=HERE.parent.parentDEST=ROOT/"build"shutil.rmtree(DEST, ignore_errors=True)
withopen("pyproject.toml", "rb") asfp:
META=tomllib.load(fp)
py2exe.freeze(
console=[],
windows=[
{
"dest_base": NAME,
"script": "myapp/gui.py",
},
],
data_files=None,
zipfile=None,
options={
"dist_dir": DEST,
"includes": [
"charset_normalizer.md__mypyc",
],
},
version_info={
"project_name": NAME,
"version": META["project"]["version"],
"description": META["project"]["description"],
},
)
nsis_config=f"""\!define exe '{NAME} Installer.exe'; Comment out the "SetCompress Off" line and uncomment; the next line to enable compression. Startup times; will be a little slower but the executable will be; quite a bit smallerSetCompress Off;SetCompressor lzmaName '{NAME}'OutFile '${{exe}}';SilentInstall silentAutoCloseWindow falseShowInstDetails show;Icon 'icon.ico'Section '{NAME}' SetOutPath '$PROGRAMFILES64\{NAME}' File /r "{os.path.abspath(DEST)}\\*" CreateShortCut '$DESKTOP\{NAME}.lnk' '$PROGRAMFILES64\{NAME}\{NAME}.exe'SectionEnd"""withopen(ROOT/"install.nsi", "w+") asfp:
fp.write(nsis_config)
Locally I would run (in a pipenv virtual environment):
$ pipenv run python scripts/build.py
And then use NSIS GUI application to make an installer from the generated install.nsi file. This works on that and other windows machines.
However, this is the Github action that has the path issue (cut down for brevity):
Hi,
I'm a little unsure the best place to put this, as I'm using
py2exe
andnsis
to freeze and install a project. I'm not to sure which side of the chain I should/can resolve this from.I'm able to
py2exe.freeze
my project, and launch it via the created*.exe
on my Windows machine. I'm also able to create an installer which install the application to Program Files, and creates a desktop shortcut, all from my development machine.However, when I go to move that workflow over to a GitHub Action, when I install the application from there I get a ModuleNotFoundError for my applications namespace/module/package (unsure the technically correct term there).
For example, I have a project with the structure like:
And the errors are for the import of my package e.g.
from myapp.utils import *
.To get around this I tried to programatically add the module/package to python
sys.path
usingsys.path.append(os.path.dirname(__file__))
as a kind of hacky solution, but actually that ends up with an error saying__file__
doesn't exist, and if I meant to say__name__
.I'm unsure either the correct way to solve this, or a hack way to solve this at the moment; open to either.
The differences in the freezing are that when ive done it on a local development machine (that works), I've done this in a virtual environment. When I've
py2exe.freeze
in the GitHub action, that's been from the system install or python. Not really sure any other differences that would cause problems.Ideally there's a way of fixing the this so the
myapp
module is appropriately added to thePYTHONPATH
. But otherwise, if I need to hard code in asys.path.append(<path>)
, I'm not sure where that path would be in a post-frozen project.Would appreciate any pointers if anyone has experience with this. Thanks.
Here's the build script I use, if it helps give any more context:
Locally I would run (in a pipenv virtual environment):
And then use NSIS GUI application to make an installer from the generated
install.nsi
file. This works on that and other windows machines.However, this is the Github action that has the path issue (cut down for brevity):
The text was updated successfully, but these errors were encountered: