If you create virtualenv, switch to it, install some packages, required by your twisted application and try to run this app using twistd - you'll get some errors about importing modules. AFAIU this happens because Gentoo has modified version of twistd, which restarts itself and loses PYTHONPATH set while in virtualenv Reproducible: Always Steps to Reproduce:
I can confirm the Gentoo wrapper scripts cause these problems. It executes /usr/bin/python2.7 instead of $HOME/.virtualenvs/$ENV/bin/python2.7 for me. I notice the same thing with ipython for example. I think the following line should look in $PATH instead of a fixed path: python_interpreter_path = "/usr/bin/%s" % python_interpreter
still a problem with twisted-11.0.0 and virtualenv-1.9.1-r1 Workaround: python `which twistd-${pyabi}` ${twistd_args} Note ${pyabi} is the python abi you created the virtualenv with.
reproducer:: # emerge twisted-core virtualenv $ python -c 'import txjsonrpc' 2>&1 | grep 'No module' >/dev/null || (echo "precondition fail" && exit 1) $ virtualenv --system-site-packages tx $ cd tx $ . ./bin/activate $ echo "import sys\nprint sys.path\nimport txjsonrpc\nsys.exit()" > a.tac $ twistd -y a.tac $ python `which twistd` -y a.tac
fix at https://bitbucket.org/yaccz/python-exec/commits/86f61cdc034962970a54559ac019c536b54eee77
Mixing system-installed stuff with virtualenv is plain unsupported. And even then, python-exec is not the place for hacks to support random Python environments. If you change twistd script to use '/usr/bin/env python...' rather than '/usr/bin/python...', it works as you want it to. Feel free to start encouraging people to use that shebang.