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

Create a section about "freezing" in docs #167

Open
maxtepkeev opened this issue Mar 12, 2017 · 0 comments
Open

Create a section about "freezing" in docs #167

maxtepkeev opened this issue Mar 12, 2017 · 0 comments
Assignees
Labels
Milestone

Comments

@maxtepkeev
Copy link
Owner

We need to create a section in our documentation about "freezing" Python-Redmine using cxFreeze, PyInstaller, py2exe etc. Thanks to @vlegoff we already have a nice explanation about how to do this for cxFreeze:

There are two obstacles to using python-redmine with cxFreeze. Both can be fixed.

  1. The redmine.resources module isn't automatically exported by cxFreeze when freezing the program, for some reason.

  2. The requests package used by python-redmine needs an additional file with permissions.

The first problem will raise a ResourceError when trying to load any manager, due to the dynamic import in managers.py. This fails, because redmine.resources isn't placed in the library.zip created by cxFreeze. It's just a matter of telling it to do so:

setup(
name = "...",
version = "0.1",
description = "...",
options = {'build_exe': {
"packages": ["redmine.resources"],
}},
executables = [...],

)

That's it.

The second problem is a bit more annoying. The 'requests' package needs the 'cacert.pem' file, but if I understood correctly, it tries to load it from a location that is no longer valid when cxFreeze freezes the program. The solution is to include 'cacert.pem' in the setup.py script (I personally copied it right into my repository, though I don't share it, the original cacert.pem was in C:\PythonXX\Lib\site-packages\requests on Windows). When the file is copied, you need to include it as a static file in your setup.py script.

setup(
name = "...",
version = "0.1",
description = "...",
options = {'build_exe': {
"include_files": ["cacert.pem"],
"packages": ["redmine.resources"],
}},
executables = [...],

)

But that's not enough, because requests still looks for the file in an invalid location. Next thing is to tell it where to look for the file (the current directory in our case). It must be done in the code, somewhere, a place where you know requests will be called is a good idea.

import os

os.environ["REQUESTS_CA_BUNDLE"] = "cacert.pem"

All in all, it's not too complicated, but that's a list of steps to keep in mind.

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

No branches or pull requests

1 participant