takluyver / pynsist

Build Windows installers for Python applications
https://pynsist.readthedocs.io/
Other
882 stars 119 forks source link

Using requests with Pynsist - import error when distributing program #123

Closed Gretorp closed 6 years ago

Gretorp commented 6 years ago

Setting the stage:

I have a tkinter program for distribution that does a get request to pull information and then outputs some files in CSV. I do have the installer.cfg : packages=requests Everything works great on the computer that I made it on. Running it through the .launch file works, executing the .py file inside of pkgs folder words, and installing the app and running it works.

The problem:

When I go to distribute the app, the program fails at import requests. I've made sure and double checked, stripping my program.py file of all requests and executing the app alone with tkinter. It works great. Once I add that line in of import requests, despite it having the requests folder in pkgs, it never works.

pynsist Installer.cfg:

[Application]
name=Program Name
version=1.0
entry_point=program:main

[Python]
version=3.5.1

[Include]
packages = requests

My Testing limitations:

I'm working on windows 7 and have only been able to test the distribution on windows 8 and windows 10 computers. Those are the computers I need to have work however.

takluyver commented 6 years ago

Can you show the error message you get?

Where you've installed it and you're getting the error, check in the install directory - by default, that's a directory under 'Program Files'. There should be a pkgs folder in there, and that should hold the requests package as a subfolder. If that's there, then the problem is with the code loading the package. If it's not, there's a problem with building or running the installer.

Gretorp commented 6 years ago

I fixed it! Thanks for pushing me to the right direction.

Here's what happened:

I had the request package included in pkgs. I looked at the error and realized it was erroring out at a urllib3 statement inside of requests.

I then realized I needed the requests dependencies!

My new installer.cfg looks as following:

[Application]
name=Program Name
version=1.0
entry_point=program:main

[Python]
version=3.5.1

[Include]
packages = requests
             #Request Dependencies below
             urllib3
             chardet
             certifi
             idna

Once I included all of those, it was able to port to computers that didn't have any previous python stuff on it.

Thanks for taking the time takluyver. Once you asked for the error message it lead me to the problem. I just looked at the error before and saw requests failing at importing and fixated on that.

takluyver commented 6 years ago

Aha, that makes sense. Thanks for following up with details of how you fixed it.

I know this requirement to list every dependency manually is a bit of a pain. Before making Pynsist, I used tools which try to automatically detect dependencies and include them. But my experience is that that goes wrong often enough that it's more confusing than helpful - you still have to specify some dependencies manually, but it's not obvious why that is or how to do it. So Pynsist (for now) makes you manually specify every package to be included.