12

I'm making a small script to generate an HTML file. For this purpose, I'm using jinja2.

This is my script (found in the jinja2 documentation):

# -*- coding: utf-8 -*-

from jinja2 import Environment, PackageLoader

env = Environment(loader = PackageLoader('monapplication', 'templates'))
template = env.get_template('index.html')
print(template.render(message = "Bienvenue sur mon site !"))

The package "monapplication" contains the folder "templates" where my index.html file is located.

But when I run the script, I get this error:

"NotImplementedError; Can't perform this operation for unregistered loader type."

I did some research, but I didn't find any solution for my problem.

My OS is Windows 10.

1

4 Answers 4

32

I had the same issue. The problem was that 'monaaplication' was known as a directory and not a python package.

Try to add an __init__.py file to the directory 'monaaplication'. (This is what tells Python to treat this directory as a package.)

2
  • As of Python 3.3, empty __init__.py files are no longer needed to designate a directory a package. This answer is still correct, but the reasoning isn't: today, this is only a requirement in setuptools, not python itself. Jun 3, 2020 at 11:40
  • 1
    I am with Python 3.6 here and adding __init__.py to the root of the package has made this error to go away. So it is still actual as a matter of a fact. Oct 22, 2020 at 9:57
2

Steps to convert .py to .exe using cx_Freeze

Install cx_Freeze, (open your command prompt and type pip install cx_Freeze. Install idna, Create a new python file named setup.py on the current directory of your script(.py file). In the setup.py file, copy the code below and save it. With shift pressed right click on the same directory, so you are able to open a command prompt window. In the prompt, type python setup.py build If your script is error free, then there will be no problem on creating application. Check the newly created folder build. It has another folder in it. Within that folder you can find your application. Run it. Make yourself happy. See the original script in my blog.

setup.py:

from cx_Freeze import setup, Executable

base = None    

executables = [Executable("myfirstprog.py", base=base)]

packages = ["idna"]
options = {
    'build_exe': {    
        'packages':packages,
    },    
}

setup(
    name = "<any name>",
    options = options,
    version = "<any number>",
    description = '<any description>',
    executables = executables
)

EDIT: you should include each imported package in your .py into packages list (ex: packages = ["idna", "os","sys"])

1

I was also getting the same issue with jinja2. It's mostly because pkg_resources is not compatible with pyinstaller and jinja2 is using pkg_resources.

Getting notimplementederror: can't perform this operation for unregistered loader type

Resolution:

I used cx_Freeze instead of pyinstaller for converting .py file into .exe, and it worked fine for me. You can refer this for cx_Freeze- How can I convert a .py to .exe for Python?

Thanks!

0
0

I got the same error when using pandas.

The problem was that a Null Provider was used so I just replaced it. I did not delve deeply into the wilds of the library, but it helped me and pyinstaller began to work correctly

try:
    from pandas.io.formats.style import Styler
except NotImplementedError:
    import pkg_resources as res
    from pyimod03_importers import FrozenImporter

    res.register_loader_type(FrozenImporter, res.DefaultProvider)
2
  • Python does not recognize pyimod03_imports, at least in my case..
    – Naveh Elya
    Jan 3, 2022 at 7:49
  • @NavehElya I used Python==3.10 and pypiwin32 pyinstaller==4.3 Jan 4, 2022 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.