Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import python module with same filename that is already imported?

I have a problem with python module import. I installed django (this can be any other module). I use this module:

from django.template import Context
# other imports
# use Context

I have a folder in my application named "utilities". In this folder I created a file "django.py" - this file contains some functions to work with django. So I import django in my module and I get error: File "...\utilities\django.py", line 1, in from django.template import Context ImportError: No module named template

like image 250
user607854 Avatar asked Feb 08 '11 09:02

user607854


1 Answers

You will have to enable absolute imports at the top of the file:

from __future__ import absolute_import

You will then have to convert the imports in the module into absolute or relative imports as appropriate.

like image 158
Ignacio Vazquez-Abrams Avatar answered Sep 29 '22 08:09

Ignacio Vazquez-Abrams