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

Including asyncpg in PyInstaller-created executable? #596

Open
makkus opened this issue Jul 6, 2020 · 8 comments
Open

Including asyncpg in PyInstaller-created executable? #596

makkus opened this issue Jul 6, 2020 · 8 comments

Comments

@makkus
Copy link

makkus commented Jul 6, 2020

I guess this is less a feature request as a call to see whether anyone has done this before (apologies if this is not the right venue for this): create an executable binary with PyInstaller that includes asyncpg. I've tried today, but had problems with the binary/C parts of asyncpg, and could not get it to include everything necessary. If anyone has done so successfully, would they mind sharing their implementation?

@Atem18
Copy link
Contributor

Atem18 commented Nov 26, 2020

@makkus Some fixes were pushed to the master branch, can you retry ?

@bvanelli
Copy link

bvanelli commented Dec 17, 2020

I had to do some tweaking in order for the imports to work properly. I haven't had any luck with the current release though, so I'm using the one on git. The following works on Python3.8, Pyinstaller 4.1:

echo "import asyncpg" > test.py
python -m pip install git+https://github.com/MagicStack/asyncpg.git@3d0e23fedfc39d5bd9732911288ad6c33147b525
pyinstaller -F --hidden-import=asyncpg.pgproto.pgproto --hidden-import=uuid --hidden-import=ipaddress test.py
./dist/test

@nono-london
Copy link

nono-london commented Feb 20, 2022

Having same issue with python 3.7 and pyinstaller 4.9 and asyncpg 0.25. And not sure how to adapt the above solution on a Windows/PyCHarm setup. Thank you for the help. Best

@bvanelli
Copy link

@nono-london have you tried one of the latest versions? It should solve the issue. Otherwise, you can use:

python -m pip install git+https://github.com/MagicStack/asyncpg.git@3d0e23fedfc39d5bd9732911288ad6c33147b525

That I'm pretty sure fixes the issue.

@nono-london
Copy link

nono-london commented Feb 21, 2022

Hi,
Thanks for the prompt answer
I have re-installed my env, with latest versions (python 3.7.9 and pyinstaller 4.9 and asyncpg 0.25) and still encounter the same issue. I use "freeze_support()" in my if __main, in case that could be an issue.
I use Windows 10 and pycharm.
asyncpg_error
I have tried and use your github link, but it results with the same issue.
What logs should I provide you in order to solve the issue?
As a note my app import a private wheel which uses asyncpg (your git provided version).
When running on pycharm with git specific version or latets version, everything works as expected.
Thanks a lot

@nono-london
Copy link

In the end I could't resolve the issue. Could be another problem with me not handling correctly asyncio with pyinstaller.
Anyway my current fix is to run the main from a bat file.

@bvanelli
Copy link

bvanelli commented Apr 6, 2022

Hmm, it's hard to say what could be going wrong, but to me main main points would be:

  • Make sure the option --hidden-import=asyncpg.pgproto.pgproto is used with pyinstaller
  • Make sure the modules are imported on the main script instead of inside functions (lazy import). I'm not sure how pyinstaller handles those cases.
  • Make sure the version is 100% correct. If you package without activating the env it will be packaged with the system package instead.

@lxcalbxy
Copy link

Hi, Thanks for the prompt answer I have re-installed my env, with latest versions (python 3.7.9 and pyinstaller 4.9 and asyncpg 0.25) and still encounter the same issue. I use "freeze_support()" in my if __main, in case that could be an issue. I use Windows 10 and pycharm. asyncpg_error I have tried and use your github link, but it results with the same issue. What logs should I provide you in order to solve the issue? As a note my app import a private wheel which uses asyncpg (your git provided version). When running on pycharm with git specific version or latets version, everything works as expected. Thanks a lot

just for debugging purposes you can add your whole code into a try-except block
e.g.:

try:
    import qwert
    import 69420
    import pussycat369killer
    
    # your clean code
except Exception as e:
    print(e)
    input()

in this case I got that I need to hook up asyncpg.pgproto.pgproto.

in 2023 I am using:
asyncpg==0.22.0.dev0+3d0e23f
pyinstaller==5.13.2
Python==3.10.6
pip==23.2.1

this command helped me out: pyinstaller -F --hidden-import=asyncpg.pgproto.pgproto --hidden-import=uuid --hidden-import=ipaddress app.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants