I have a python package that I'm writing and I'm having an issue where the standard library is being imported instead of my files because of name clashes.
For example, a file structure like below:
package/__init__.py
# No data in this file
package/module.py
#!/usr/bin/env python
print 'Loading module.py'
import signal
package/signal.py
#!/usr/bin/env python
print 'Loading signal.py'
I get the following results when I run this:
$ ./module.py
Loading module.py
I would like to get:
$ ./module.py
Loading module.py
Loading signal.py
The actual question:
So, when I run module.py, it's import signal
goes to the stdlib version. How am I able to force module.py to import signal.py instead?
As noted in the tags, this needs to be able to run on python-2.4.3. While that is an old version, it's what is included in RHEL 5.
Some additional information
Just for a bit more information, I explicitly have the following setup:
[10:30pm][~/test] tree .
.
|-- package
| |-- __init__.py
| |-- module.py
| `-- signal.py
`-- script
[10:30pm][~/test] cat script
#!/usr/bin/env python
from package import signal
[10:30pm][~/test] cat package/__init__.py
[10:30pm][~/test] cat package/module.py
#!/usr/bin/env python
print "Loading module.py"
import signal
[10:30pm][~/test] cat package/signal.py
#!/usr/bin/env python
print "Loading signal.py"
[10:30pm][~/test] python ./script
Loading signal.py
[10:32pm][~/test] python ./package/module.py
Loading module.py
[10:32pm][~/test] python -m package.module
python: module package.module not found
Please note that when I ran ./package/module.py that the print statement in ./package/signal.py was not fired. This implies that the signal that was loaded is the one from the stdlib.
./configure; make; make install
. Blau – Hypophosphate$ python2 -m package.module
=>Loading module.py Loading signal.py
– Eppes-m
works properly only on Python2.6+ docs.python.org/whatsnew/… – Pardoner