Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staticx and pyinstaller - confused #5607

Closed
Zeebzog opened this issue Mar 6, 2021 · 6 comments
Closed

staticx and pyinstaller - confused #5607

Zeebzog opened this issue Mar 6, 2021 · 6 comments

Comments

@Zeebzog
Copy link

Zeebzog commented Mar 6, 2021

I have read through the various bug report etc. but I am confused about how to solve the issues.
I want to use staticx on a single file that I have created by pyinstaller - F main.py, for example.
I get the following error :
[332529] Cannot open self /tmp/staticx-OOLCLA/main or archive /tmp/staticx-OOLCLA/main.pkg
Main simply spins up a flask app
I thought I could fix this by simply going back to version 4.0 of pyinstaller since this had a bootloader compiled with the correct pie settings for this this to work.
However in my case it does not.
Are there any definitive instructions of how to get staticx to work with pysintaller?
I appreciate any assistance, I am trying to get a 300+MB docker container down to something that is more sensible.

@bwoodsend
Copy link
Member

Your using onefile mode - that's never going to work because a onefile application is really an archive. PyInstaller already bundles anything that your code is linked against so its unlikely that staticx will find anything extra.

@Zeebzog
Copy link
Author

Zeebzog commented Mar 6, 2021

Thank you for your response.

I agree that staticx will not find much of anything else, which is perfect, but it should bind in Glibc, this will allow me to go to a smaller container by using the scratch image for instance, as discussed in this blog:
https://medium.com/analytics-vidhya/dockerizing-a-rest-api-in-python-less-than-9-mb-and-based-on-scratch-image-ef0ee3ad3f0a

The problem I seem to have has been raised previously here:

JonathonReinhart/staticx#71

and suggests that rolling back to pyinstaller 4.0 fixes the issue. For me this did not work.

If I am totally off the mark then happy to try to a different approach, at the moment I have a small program in a 300 Mb linux container.

@bwoodsend
Copy link
Member

If your already using docker and trying to produce a docker image, why bother with PyInstaller at all? You could just take a Python docker base image, install your code into it then ship the resultant image. That should run universally AFAIK.

@Zeebzog
Copy link
Author

Zeebzog commented Mar 6, 2021

I agree I could do that, but it would be a docker container whose size would be quite large. I have a number of these containers to ship and each one is around 300+ Mb when installed.
I would like the containers to be a lot smaller, 60Mb at most and hopefully more around 10Mb.
If I can make the dependencies statically link into the exe the less space I will require, well that is the theory.
This is not motivated by having a working container, that is easy, this is about minimising the size of each container so I can have lots of them in a microservice architecture

@rokm
Copy link
Member

rokm commented Mar 6, 2021

The motivation and reasons for using staticx aside, the Cannot open self <program> or archive <program.pkg> issue with staticx-processed binaries should be fixed by #5511. So it should work with develop branch, but you need to rebuild the bootloader. E.g.,

git clone https://github.com/pyinstaller/pyinstaller.git
cd pyinstaller/bootloader
python ./waf configure all  # compile bootloader
pip install ..  # install PyInstaller from source, with rebuilt bootloader

And then rebuild your onefile program and process it with staticx.

@Zeebzog
Copy link
Author

Zeebzog commented Mar 6, 2021

Thank you rokm for your response. I followed your instructions which worked perfectly and resulted in pyinstaller-5.0.dev0 being built and installed.
Unfortunately when I build the staticx and run it, I still get [7519] Cannot open self /tmp/staticx-FIliEF/xxxx or or archive /tmp/staticx-FIliEF/xxxx.pkg


Please ignore the above, created a new project with exactly the same code and when built it now works! Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants