为 Python 安装 Twisted 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31457009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:01:27  来源:igfitidea点击:

Error installing Twisted for Python

pythontwistedfailed-installation

提问by Seaver

I tried installing twisted on an Ubuntu VM like this:

我尝试在 Ubuntu VM 上安装扭曲,如下所示:

pip install twisted

pip 安装扭曲

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.

我不是一个真正的程序员,只是一个业余爱好者,所以这是我的想法。谷歌搜索显示它需要 python-dev 和 build-essential。我安装了这两个,但安装 Twisted 仍然出现与以前相同的错误。

Any thoughts?

有什么想法吗?

回答by Glyph

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

作为 Twisted 的维护者,很抱歉您在安装时遇到了糟糕的体验。成为业余爱好者不是您的错-它应该可以正常工作:-)。

It would be helpful if you could include more complete logs when reporting an installation error. Presumably there is some other stuff that piptried to do. For example, when I tried to reproduce this error, I saw something similar, but right above it it said

如果您可以在报告安装错误时包含更完整的日志,将会很有帮助。大概还有一些其他的东西pip试图做。例如,当我试图重现这个错误时,我看到了类似的东西,但在它的正上方它说

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-essentialand python-dev. If you have the ability to apt-get installstuff, 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 twistedby 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'tdo 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 reallyshouldn'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 :).

  1. 您安装build-essentialpython-dev。如果你有能力做apt-get install东西,也许考虑一下apt-get install python-twisted?这将安装旧版本,但由于您的操作系统供应商支持它,因此几乎可以保证正常工作。
  2. 您可以安装到virtualenv 中。安装到 virtualenv 将软件包与系统 Python 环境隔离开来,并减少可能出错的事情的数量。通常会出错的一件事是,pip install twisted它本身会尝试安装到您系统的 Python 包管理器中,这就是我上面粘贴的错误的含义。然后你可以这样做:

    $ sudo apt-get install python-virtualenv
    $ virtualenv my-fun-env
    $ source my-fun-env/bin/activate
    (my-fun-env)$ pip install twisted
    

    这将仅在虚拟环境中安装 Twisted,您可以轻松地将其丢弃并重新创建以试验新版本的 Twisted,因此您无需更改整个系统即可尝试。

  3. 要这样做:“解决”此问题的一种流行方法是执行sudo pip install .... 这可能表面上看起来可行,但它也有损坏计算机的风险,除非您可以轻松地重新安装操作系统来修复它,否则您真的不应该这样做。如果另一个回答者提出了这一点,请忽略它们。使用我的另外两个建议修复之一:)。

回答by anjaneyulubatta505

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