I'm trying to re-organize my Python project by moving scripts from the package directory into a top level script directory. After these changes, this is what my project hierarchy looks like:
MyProject/
setup.py
scripts/
my_package.py
my_package/
__init__.py
module_foo.py
Notice how the script and the package have the same name.
The script my_package.py
looks something like this:
# MyProject/scripts/my_package.py
import os
try:
import my_package
print os.path.abspath(my_package.__file__)
except ImportError as e:
print e
When we run the above script the interpreter imports the current module rather than the package of the same name (note: the package my_package
has already been installed into site-packages
as an egg and our virtual environment is properly activated.)
How can I import the package my_package
from the script my_package.py
given they have the same name?
Other Technical Info:
- Python 2.7.3
- Ubuntu Server 12.04 LTS
- VirtualEnv 1.11.6