Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotImplementedError: Can't perform this operation for unregistered loader type

Tags:

python

jinja2

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.

like image 487
Wivi0 Avatar asked May 06 '16 09:05

Wivi0


2 Answers

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.)

like image 131
Kreu Avatar answered Sep 28 '22 19:09

Kreu


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"])

like image 42
Pritam Mondal Avatar answered Sep 28 '22 19:09

Pritam Mondal