18

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?

2
  • 2
    Did you install the dev packages for the correct version of Python? Run python --version if the version is 3.x.x then you might have to use install python3-dev and then pip3 install twisted. FYI Twisted hasn't been fully ported to Python 3. Commented Jul 16, 2015 at 22:08
  • Thanks, notorious. My version is 2.7.3, so I presume the other packages were the right ones. Commented Jul 17, 2015 at 19:33

2 Answers 2

15

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:

  1. You installed 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.
  2. 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.

  3. 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 :).

Sign up to request clarification or add additional context in comments.

4 Comments

Glyph, thanks so much for the detailed help! Um, when I saw you guessed correctly about "error: could not create.. Permission denied," I impulsively ran the command again with sudo... forgetting that was exactly what you said not to do. It said "Successfully installed twisted-15.2.1," so that's at least superficially a good sign. If the VM breaks, well, that'll teach me to follow directions slowly and methodically next time.
Well, you'll have a working Twisted - for now :). The problems come later when you need to apply security updates or install a package into apt that depends on Twisted. So as long as it's a VM that you can easily re-create, you should be fine.
Thanks for using Twisted!
If you're using Python3 on Ubuntu make sure to sudo apt-get install python3-dev.
8

I have fixed it by installing the folowing packages

sudo apt-get install python-dev python-pip libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.