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
Issue about "Can't perform this operation for unregistered loader type" #752
Comments
Does any one know this problem? Is it nuitka issue or my problem? Thank you! |
I didn't find where the error message comes from by looking ath CPython source code. The example code is good enough though, I will eventually try and reproduce it. Doesn't look like an error of yours, probably something pkgutil or pandas would do. Nuitka has its own loader type, and registers it in some places, but potentially there are more. |
Thank you very much Kay. If i did not set the Excel file style, every thing is OK. |
Ok, great. Yes, pkgutil supports loading data files for packages. It would be your responsibility to make sure they are there, but the error seems to indicate that it's not accepting the nuitka loader to do it. We have implemented |
@kayhayen |
I can reproduce this with Python 3.8.5, Nuitka 0.6.10.5, pandas 1.1.3 on Windows 10. The MRE is (note that the pandas._libs.* imports are needed because of e.g. #837) with the relevant line
I would be happy to help with further debugging and testing. Where would be the best place to look into the Nuitka loader?
|
This is very helpful @fleimgruber as it doesn't involve standalone mode, this is likely more workable. This should be as easy as having a plugin that post load of |
@kayhayen glad to help. Could you give me a rough idea on where in the code registering should be done? Or do we need to create the mentioned plugin (still need to get familiar with the Nuitka concepts)? Also, what do you suggest would be a good dev / test setup for this? I would work on Nuitka master, but building and then executing the binary to see the effects is not really practical. Being able to reproduce this without building would be a good first step. WDYT? I would then look into the relevant docs and see what I can come up with: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#supporting-custom-importers |
I found Nuitka/nuitka/plugins/standard/NumpyPlugin.py Line 176 in 0083a93
|
I don't think it has anything to do with numpy @fleimgruber but pkg_resources. I think a better starting point would be the
|
You would have to mimic that, and handle I would appreciate if you could take this on. I think it's as simple as making sure to execute a bit of code right after Do not use standalone mode while developing it, that leaves the resources at where |
Thanks for the pointers and thoughts, I will try to look into this. |
I tried to reproduce this only using jinja2 (copied the relevant lines from Pandas) as you suggested via import jinja2
def main():
loader = jinja2.PackageLoader("pandas", "io/formats/templates")
env = jinja2.Environment(loader=loader, trim_blocks=True)
template = env.get_template("html.tpl")
if __name__ == '__main__':
main() and the command
but that errors with a C compilation warning:
|
Putting that aside for now and working with your actual suggestion ( def main():
from pkg_resources import get_provider
package_name = "pandas"
provider = get_provider(package_name)
p = 'io/formats/templates/html.tpl'
provider.has_resource(p)
if __name__ == '__main__':
main() which should essentially be what jinja2 (v2.11.2, note pallets/jinja#1182) would be doing. Also, jinja will stop using |
For reference, pkg_resources support for pyinstaller report pyinstaller/pyinstaller#4881 and PR pyinstaller/pyinstaller#5284. |
That debug mode error message is something I am looking into. As for the reproducer, maybe too much guessing from my side. I will also look at that PR code, maybe it's another method needed. |
Just a quick follow-up. Regarding the error in #752 (comment) and your #752 (comment), I tried again today with Nuitka 0.6.13.3 and I don't see the debug mode error anymore. But after
I see essentially the same error as in #752 (comment):
|
I did another test with
with the command
and got a different error, this time directly from
|
I have the same problem about the Jinja2. |
I have made successful deployments with Jinja2 for all kinds of loaders now. I think the |
Trying out the reproduce right now, fodder for anti-bloat tuning definitely, lets see if this still happens. I have plans on specializing |
I add the command |
This pulls in a lot of numba modules, most of which are of course very irrelevant, e.g. analysing elf binaries, this has taken a few iterations so far already, but will shapen anti-bloat for this side of numba. I don't think I usually see it used from Pandas imports, but maybe I didn't notice yet. |
We try to have required package data automatically included through our Yaml files. Not sure if absent data files show with the symptom described, but possibly they do, which would be ugly, but what can we do. There is a bigger changing coming, where some sort of interactive mode, will trace files that didn't exist, DLLs that failed to be found, etc. and give proper warnings at runtime, but that's probably months away still. |
When I just tried with the option mentioned in #752 (comment) I get this on executing the resulting binary:
where PackageLoader is from jinja2 I guess. Also, I am using Nuitka 0.9.6 and Python 3.8.11. |
This will probably be reproducible, the loader has gained more compatibility, I am now trying your reproducer from earlier @fleimgruber which seems like it might point out, what to do, if anything still. |
Additional information:
|
So, new Jinja2 package loader doesn't use pkg_resources anymore in its package loader, but instead expects a registered loader class, for which now the |
Using latest factory, I don't see the jinja2.PackageLoader error anymore. Will test more after #1710. |
Somehow now this is failing again, even with 1.1rc (factory). I will test more and come up with a MRE. Just to be sure: it is enough to remove |
Just tested with this MRE: import pandas as pd
from pandas.io.formats.style import Styler
def main():
inp = input('enter')
if __name__ == '__main__':
main()
|
Since I am using the factory branch from a local git clone right now, I might as well set up a proper development environment for Nuitka. I am using VS Code anyways for the project to be compiled with Nuitka. Next I would try to mirror the workflow you have when testing such issues yourself. Are you using a Nuitka virtualenv for development and do you debug MREs in VS Code? |
Running Nuitka inside Visual Code is an open issue, that is not solved yet. It insists on a clean environment, and Visual Code will not work yet. I suspect, that Jinja2 package loader got changed in a later release. The MRE you gave does have a fix, that but it doesn't affect the Jinja2 anymore, because they decided, they are going to do their own file system based stuff. They insist on the package folder and the data files to exist. If you include the files it expects, it will not give this error, which if course, can be very misleading. I managed to get commercial file embedding to work without the folder, and non-commercial will have the folder, well, for as long, as a package data file is included. I am going to use your MRE there, seems that renderer there is missing some data files, that we might want to add by default. |
Your question regarding caching @fleimgruber currently I am not aware of any issues that are caused by caching, I never disable them myself and try to work with them being on. |
But essentially, what happened is that this issue morphed from a |
What I am doing right now is installing the MRE dependencies into a virtualenv (managed by Poetry) and specifying that virtualenv for VS Code. Then I use e.g. this in VS Code "configurations": [
{
"name": "Issue 752 standalone",
"type": "python",
"request": "launch",
"program": "nuitka/__main__.py",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["--standalone", "issue/752.py", "--mingw", "--show-progress", "--plugin-enable=numpy", "--include-package-data=bokeh"]
}, which allows me to to set breakpoints and debug Nuitka using the VS Code visual debugger. |
Mhm, supporting 3rd party libs when they significantly change sounds like a lot of headaches. |
By "semi-real" you are referring to your comment about package folder and including data files in #752 (comment)? I guess you are at it already using the MRE and including some data files by default. Let me know if I can help there now that my dev env is set up. Otherwise I would continue testing any fixes. |
Basically it's not only about finding out what files are required there, nothing too difficult. We will have to describe the process at some point. In the case of Jinja2, the misleading code will become subject to changes through anti-bloat. I invite you to check out the yaml files in Nuitka plugins folder, they modify some modules already (called anti-bloat) or specify data files to be included for packages that require them absolutely. |
One thing, about standalone that is bad, is now it doesn't include the traceback referenced source code, not even as an option, such that one gets to manually locate from a standalone traceback the source code in question. That makes the task a bit harder than necessary. |
Thanks for the pointers. I do have a lead, will try this some more tomorrow. |
If I read https://nuitka.net/doc/developer-manual.html#the-git-flow-model correctly, I should branch off of My plan so far and if I understand things correctly is to create |
Well, the data files plugin is intended for that, actually you only would need to add content to the yaml, and code is very unlikely for data files to be included. Also there is an option for a user yaml file, so you do not immediately have to edit the yaml file mentioned, but can provide the proper snippet yourself. Visual Code will have a schema that it can apply, but I think it does not do it for user yaml files, we do not use patterns there, maybe Visual Code does not support that, not sure. |
Thanks for the explanation. So looking at the relevant lines in the pandas module in question IMHO the yaml should look something like: - module-name: "pandas"
dirs:
- "io/formats/templates"
data-files:
patterns:
- "io/formats/templates/*.tpl" which when used as
Leads to an assertion error here which becomes clear when looking at the comment above it. So is the plan to use |
Modules can only have a single configuration, merging is not yet supported, this hurts here. I will need to implement that. I am pushing a hotfix currently, that adds the config as follows:
Currently on factory, but will be in 1.0.1. Also, the Sorry for overtaking you here, not a good thing to encourage contributions. Would you be willing to try and examine code and config for examples of how to do things, and add that to the documentation in a PR? I think, this should have been very straightforward for you by now, and that's the missing bit. |
@kayhayen sorry for not responding sooner to your question! I just had a look again and found some docs on: https://nuitka.net/doc/nuitka-package-config.html and also some here: I skimmed the docs and could not find anything related to config merging (it may have been implemented in the meantime?). I saw some placeholders for examples, so I could try to fill those, but the examples concerning my use cases are already included in the shipped |
The first doc was online at that point for only a few hours. :-) You mean Yaml config file merging for the same module? No, unfortunately that is not done yet, it's an omission that I need to work on. Actually I ought to change my personal workflow here from creating a user provided file, testing that, and then merging it with a tool automatically into the official file. Merging in the sense that multiple files work, that is done. |
:-) always surprised about those coincidences. Yes, I was specifically referring to merging for the same module - but I can see that it's tricky. For the common packages, PRs to Nuitka are the way to go and user modules won't be conflicting with Nuitka module configs. So I guess it's a pragmatic "no need to implement at this point". And having the ability to use multiple files is nice, thanks! I will try this some more for a personal project that needs it's template files included in that way. |
There is also command line options for including data files by directory, by pattern, etc. doesn't have to Yaml for this, only DLLs have no options. |
My script runs correctly and output what I wanted.
But I packed my python scripts to exe file, it raised "Can't perform this operation for unregistered loader type" when I run the exe file.
my nuitka command:
python -m nuitka --mingw64 --standalone --show-progress --recurse-all --enable-plugin=numpy --include-package=openpyxl --include-package=markupsafe --include-package=jinja2 --follow-imports --output-dir=exeFiles mytest.py
my envirionmnet:
Windows 7
I installed all the packages(nuitka, jinja2,...) by pip
python -m nuitka --version
0.6.8.4
Python: 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 23 2018, 23:31:17) [MSC v.1916 32 bit
(Intel)]
Executable: C:\Program Files (x86)\Python36-32\python.exe
OS: Windows
Arch: x86
my source code:
#===============mytest.py=========================
The text was updated successfully, but these errors were encountered: