pyngrok downloads ngrok each time i run the pyinstaller executable. How can i make it download ngrok only once?

502 views Asked by At

When i run the script first time it downloads the file ngrok.exe in the python38\Lib\site-packages\pyngrok\bin folder and running the script second time it uses the downloaded ngrok.exe which is expected.

But when i make an executable file , then it downloads ngrok each time the user runs the executable file.

So how can I tell pyngrok to download the ngrok.exe only the first time when the executable executes and then use the downloaded file instead of downloading it each time?

here is my code snippet:

pyngrok_config = PyngrokConfig(region="au")
ngrok.set_auth_token(auth_code)   # auth_code is a string
tunnel = ngrok.connect(4444, "tcp", pyngrok_config=pyngrok_config)
1

There are 1 answers

0
alexdlaird On

As you observed, pyngrok should only download the ngrok binary one time. If it is downloading it over and over, it's probably being downloaded to a cached location and thus being blown away each time the application exits.

How this is happening would be pretty dependent on how your executable is built, so we'd need more information there to troubleshoot that specifically. However, a better solution would be to simply look at modifying your ngrok_path so where the binary is downloaded to is set explicitly, as documented here. As a bonus, this would also help you with debugging.

from pyngrok.conf import PyngrokConfig
from pyngrok import conf

conf.set_default(PyngrokConfig(region="au", ngrok_path="/usr/local/bin/ngrok"))