Am getting the below error when executing python protocols/smpp/test/test_post_upgrade.py:
Traceback (most recent call last):
File "protocols/smpp/test/test_post_upgrade.py", line 1, in <module>
from protocols.smpp.proto import *
File "/tmp/Wass/protocols/smpp/proto.py", line 1, in <module>
from twisted.internet import defer, reactor
ImportError: No module named internet
Here’s my tree:
/tmp/Wass$ tree
.
├── __init__.py
└── protocols
├── __init__.py
├── __init__.pyc
└── smpp
├── __init__.py
├── __init__.pyc
├── proto.py
├── proto.pyc
└── test
├── __init__.py
└── test_post_upgrade.py
3 directories, 10 files
Here’s the content of the principal files:
/tmp/Wass$ cat protocols/smpp/proto.py
from twisted.internet import defer, reactor
/tmp/Wass$ cat protocols/smpp/test/test_post_upgrade.py
from protocols.smpp.proto import *
/tmp/Wass$ cat protocols/smpp/__init__.py
__import__('pkg_resources').declare_namespace(__name__)
For information, i can resolve this issue by one of these actions:
- Emptying
protocols/smpp/__init__.py, but this is usefull for the whole project so i can just empty this file, my project will no more run .. - Renaming
protocols/smppto anything else, for exampleprotocols/totowill work (with changingprotocols/smpp/test/test_post_upgrade.pytofrom protocols.toto.proto import *
The second solution is so confusing as i dont have any smpp/proto.py in my system that can cause a conflict …
Here’s a simpler representation of the issue:
Wass/
Wass/__init__.py
Wass/protocols/
Wass/protocols/smpp/
Wass/protocols/smpp/__init__.py
Wass/protocols/smpp/test/
Wass/protocols/smpp/test/__init__.py
Wass/protocols/__init__.py
Wass/protocols/smpp/test/test_post_upgrade.py:
> from Wass.protocols.smpp.proto import SMPPClientProtocol
Wass/protocols/smpp/proto.py
> from twisted.internet import defer, reactor
>
> class SMPPClientProtocol:
> pass
Execution outcome:
$ echo $PYTHONPATH
:/opt/smpp.twisted/:/opt/smpp.pdu/:/tmp/Wass/
python /tmp/Wass/protocols/smpp/test/test_post_upgrade.py
> Returns the same problem above
There are a number of potential issues here.
Wassreally supposed to be a package, or is it an entry onsys.path? If it’s really a package, you should be adding/tmpto yourPYTHONPATH; if it’s a path entry, you should be adding/tmp/WasstoPYTHONPATH, and deleting/tmp/Wass/__init__.py*.pythonon modules within a hierarchy directly. It confuses the issue.Wassis going to continue to be a package (i.e. contain an__init__.py), you should adjust your imports to befrom Wass.protocols.smpp.proto import ....import *. It’s just confusing; someone reading your code has no idea what names are supposed to come from what module.Ultimately I think that the problem you’re seeing is caused by the combination of a top-level module named
protocols, which conflicts with several modules within Twisted, and the use ofimport *which is probably pulling in another name likebasicorsmtporpop3into that namespace and clashing with something, then the magic of namespace packages combines with it all to create an explosion. I can’t be more specific than that without seeing the actual code that triggers the problem :).Whenever faced with an issue like this though, it’s good to take a step back and make sure that the working directory, the script directory, and PYTHONPATH are all separated out so you know exactly how your code is being imported. Specifically, I’d recommend doing something like this:
Hopefully that will work out better for you.