asyncpg icon indicating copy to clipboard operation
asyncpg copied to clipboard

Including asyncpg in PyInstaller-created executable?

Open makkus opened this issue 5 years ago • 8 comments
trafficstars

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?

makkus avatar Jul 06 '20 20:07 makkus

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

Atem18 avatar Nov 26 '20 00:11 Atem18

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

bvanelli avatar Dec 17 '20 15:12 bvanelli

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

nono-london avatar Feb 20 '22 23:02 nono-london

@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.

bvanelli avatar Feb 21 '22 08:02 bvanelli

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 avatar Feb 21 '22 10:02 nono-london

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.

nono-london avatar Apr 04 '22 16:04 nono-london

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.

bvanelli avatar Apr 06 '22 07:04 bvanelli

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

lxcalbxy avatar Sep 20 '23 05:09 lxcalbxy