I tried installing twisted on an Ubuntu VM like this:
pip install twisted
It downloads and starts installation, but gets this error:
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-SQhfJz/twisted/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ItHrMV-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-SQhfJz/twisted
I'm not a real programmer, just a hobbyist, so this is way over my head. Googling it showed it needs python-dev and build-essential. I installed both of those, but installing twisted still got the same error as before.
Any thoughts?
As a maintainer of Twisted, I'm sorry you're having a bad experience installing it. It's not your fault for being a hobbyist - it should just work :-).
It would be helpful if you could include more complete logs when reporting an installation error. Presumably there is some other stuff that pip
tried to do. For example, when I tried to reproduce this error, I saw something similar, but right above it it said
error: could not create '/usr/local/lib/python2.7/dist-packages/twisted': Permission denied
which was the real bug. Is that what your installation attempt said? If so, then you have two options:
build-essential
and python-dev
. If you have the ability to apt-get install
stuff, perhaps consider just apt-get install python-twisted
? This will install an older version, but since it's supported by your operating system vendor it's almost guaranteed to work.You can install into a virtualenv. Installing into a virtualenv isolates packages from your system Python environment and reduces the number of things that can go wrong. One thing that can popularly go wrong is that pip install twisted
by itself will try to install into your system's Python package manager, which is what the error I pasted above means. You can then do:
$ sudo apt-get install python-virtualenv
$ virtualenv my-fun-env
$ source my-fun-env/bin/activate
(my-fun-env)$ pip install twisted
this will install Twisted inside a virtual environment only, which you can easily throw away and re-create to experiment with new versions of Twisted, so you don't have to make changes to your whole system to try things out.
Don't do this: one popular way to "fix" this problem is to do sudo pip install ...
. This may superficially appear to work, but it also carries the risk of breaking your computer, and you really shouldn't do it unless you can easily reinstall your operating system to fix it. If another answerer suggests this, ignore them. Use one of my other two proposed fixes :).