I have found an… odd collision of problems. I have the following packages installed:
- Google protocol buffers (
- The google package from PyPI (not affiliated)
Twisted provides an application system which lets you define
.tac files and then have
twistd handle a bunch of boiler plate (logging, background, reactor selection, etc).
twistdis installed as a Python file to my PATH (ie
- google installs
google.pyto my PATH (
- When you start
twistd, Python adds its directory (
/usr/bin) to its path
- When my application imports
google.protobuf, Python first imports
- Python finds
/usr/bin/google.pyand imports it as
- Python can’t find
So what went wrong?
twistdwas installed in such a way to allow unnecessary items into Python’s path
- google installed a
.pyfile into the PATH
- I wasn’t using a virtual environment.
I’m now considering the opinion that Python scripts should never be installed directly. Instead, they should be installed as
__main__ modules and a shell script of the form
exec python2/3 -m mypackage is installed to your PATH.