Rory Rory -4 years ago 85
Python Question

Python - Importing a global/site-packages module rather than the file of the same name in the local directory

I'm using python and virtualenv/pip. I have a module installed via pip called

(it's django-test-utils). Inside one of my django apps, I want to import that module. However I also have another file
in the same directory. If I go
import test_utils
, then it will import this local file.

Is it possible to make python use a non-local / non-relative / global import? I suppose I can just rename my
, but I'm curious.

Answer Source

Since my test_utils was in a django project, I was able to go from ..test_utils import ... to import the global one.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download