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

Can't import local module to pelicanconf.py #2111

Closed
georgiastuart opened this issue Mar 3, 2017 · 7 comments
Closed

Can't import local module to pelicanconf.py #2111

georgiastuart opened this issue Mar 3, 2017 · 7 comments

Comments

@georgiastuart
Copy link

I have a file with my custom jinja2 filters. These work fine when pasted directly into pelicanconf.py. However, when I attempt to import the module using

import jinja_custom_filters as jcf

I get the following error:

ModuleNotFoundError: No module named 'jinja_custom_filters'

I wrote a quick test file in the same directory as pelicanconf.py and jinja_custom_filters.py, and it has no problem importing jinja_custom_filters.

I've combed the documentation, but I can't find anything that would assist with this.

@georgiastuart georgiastuart changed the title Can't import local module to pelicanconf.pt Can't import local module to pelicanconf.py Mar 3, 2017
@ingwinlu
Copy link
Contributor

is jinja_custom_filters.py in your pythonpath?
whats the general layout of your setup, i.e. where is pelicanconf.py and where is your filter module?

@cropse
Copy link
Contributor

cropse commented Mar 27, 2017

It work for me

import sys
sys.path.append('.')
import jinja_custom_filters
JINJA_FILTERS = {'filter_name_in_html': jinja_custom_filters.the_filter_function}

and It work fine for me, maybe need to update the Docs?
Answer From

@drummonds
Copy link

Works for me as well. I have the problem on Windows with vritual env. Is this something to do with pelican running in a different home directory.

eg a pelicanconf.py file like this:

import sys
sys.path.append('.')
from base import *

@justinmayer
Copy link
Member

Closing due to inactivity. Please feel free to comment here if you feel the issue should be re-opened.

@deutrino
Copy link

Well, it's still broken, so maybe it should be re-opened on that basis.

@justinmayer
Copy link
Member

@deutrino: Not a very helpful comment. Most of what I’m seeing here is “works for me.” Moreover, the word “broken” is about the most information-free word imaginable in a software context.

@bedlamzd
Copy link

this workaround works, but feels more like unnecessary step and strange behavior
in my opinion import should work directly, without adding '.' to path
so the issue is that pelican don't import modules located in the same directory as pelicanconf.py
it would be nice if it could do so

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

No branches or pull requests

7 participants