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 "" - this file contains some functions to work with django. So I import django in my module and I get error: File "...\utilities\", line 1, in from django.template import Context ImportError: No module named template

-------------Problems Reply------------

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.

Use namepaces, create a in your utilities directory, so that it is package and then do import utilities.django. Btw, it is bad practice to name your module the same as std libraries or the name of package you know you are going to use. You never know when you are going to confuse yourself with which module to use.

Category:python Views:0 Time:2011-02-08

Related post

  • mod_wsgi: import python modules with the same name 2011-07-09

    This is a follow-up question to import python modules with the same name, but as the two are somewhat unrelated, it's probably better to ask a new question: I have several python projects and they all have a conf package: /some_folder/project_1/ conf

  • Return a list of imported Python modules used in a script? 2010-04-03

    I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which modules they import. As an example, if one of the files I import has the followi

  • Import python module NOT on path 2012-04-15

    I have a module foo, containing and I want to import it in IDLE or python session. How do I go about this? I could find no documentation on how to import modules not in the current directory or the default python PATH. After trying im

  • How to import python module in a shared folder? 2009-07-28

    I have some python modules in a shared folder on a Windows machine. The file is \mtl12366150\test\ os.path.exists tells me this path is valid. I appended to sys.path the folder \mtl12366150\test (and os.path.exists tells me this path is va

  • Importing Python modules from a distant directory 2009-10-15

    What's the shortest way to import a module from a distant, relative directory? We've been using this code which isn't too bad except your current working directory has to be the same as the directory as this code's or the relative path breaks, which

  • Importing Python module from the Bash 2010-03-08

    I am launching a Python script from the command line (Bash) under Linux. I need to open Python, import a module, and then have lines of code interpreted. The console must then remain in Python (not quit it). How do I do that? I have tried an alias li

  • Importing Python modules without installing - Sybase ASE 2010-06-08

    I need to use the Sybase Python module but our SA's won't install because it's not in the repo's. I've downloaded it and placed it on the box and would just like to 'import' or 'include' the module without installing it first. - Is this possible? Fro

  • Command Line Arguments in Imported Python Modules 2010-08-25

    This is more a question of coding style, but I have a script that processes a particular file (or set of files). It would be nice to allow the user to provide those files as command-line arguments. Of course, it's possible that the user forgets to pr

  • Dynamically importing Python module 2010-09-26

    I have a trusted remote server that stores many custom Python modules. I can fetch them via HTTP (e.g. using urllib2.urlopen) as text/plain, but I cannot save the fetched module code to the local hard disk. How can I import the code as a fully operab

  • Import Python module with PyImport_ImportModuleEx for a gedit plugin 2011-06-01

    I'm learning Python and I try to use Python Markdown in a gedit plugin. Here's how my files are organized: ~/.gnome2/gedit/plugins/mytest.gedit-plugin ~/.gnome2/gedit/plugins/mytest/ ~/.gnome2/gedit/plugins/mytest/ ~/.gnome2/gedit/plugins/

  • python module installed and recognized, but unable to import it on my code or python 2.7.1 interpreter on Ubuntu 2011-08-12

    I'm stuck trying to get a python C module up and running. I'm installing deltaLDA module from Here. I followed the instructions as specified in REAMDE file. As usual, I wrote: sudo python install Everything went as expected I guess, I get th

  • How do I make Hadoop find imported Python modules when using Python UDFs in Pig? 2011-10-20

    I am using Pig (0.9.1) with UDFs written in Python. The Python scripts import modules from the standard Python library. I have been able to run the Pig scrips that call the Python UDFs successfully in local mode, but when I run on the cluster it appe

  • Importing python modules for use in only one file 2011-12-03

    More specifically let's say I have a number of .py files, with importing stuff like os, pygame, math and all my other .py files, etc. My problem is that whenever calls on one of my .py files and that file contains someth

  • Trouble importing python module despite directory appearing in the path 2012-01-03

    I'm trying to import a module into python but having difficulty. I have defined the Environment Variable PYTHONPATH which contains C:\MyModules. I get the following from Python 2.7 when I ask it about the path. >>> import sys >>> sy

  • How to import python modules from parent and sibling packages 2012-04-22

    This (or similar) question has been asked many times before, but none of the solutions offered work in my case. My project structure is like this : | project_2 | config | database data

  • Why does an imported python module stop working once multiprocessing has begun? 2011-11-23

    I have a class in which I import a module (call it myModule). Among other things, I use this module for an object it provides: myObject = myModule.ImportantObject() This object worked fine whenever I used it in the class, until I started using multip

  • Importing Python modules on Linux from an NTFS share 2011-07-22

    My problem is a difference in how Python searches for modules on Windows/Linux. I have a directory foo on a Windows 7 machine (NTFS), which I mount in a Ubuntu 10.04 virtual guest running on the same machine (via VirtualBox' guest additions). Inside

  • Checking for code changes in all imported python modules 2008-09-24

    Almost every Python web framework has a simple server that runs a wsgi application and automatically reloads the imported modules every time the source gets changed. I know I can look at the code and see how it's done, but that may take some time and

  • Importing Python modules from different working directory 2009-06-25

    I have a Python script that uses built-in modules but also imports a number of custom modules that exist in the same directory as the main script itself. For example, I would call python and has a number of imports, including: impor

Copyright (C), All Rights Reserved.

processed in 0.105 (s). 11 q(s)