【问题标题】:Python Twisted twisted.internetPython Twisted twisted.internet
【发布时间】:2017-03-20 13:19:30
【问题描述】:

我已经从 git 下载了 twisted

git clone -b 主干https://github.com/twisted/twisted.git

正如http://twistedmatrix.com/trac/wiki/Downloads 建议的那样。

然后我表演了

sudo python setup.py install

但是现在当我运行一些 python 文件时,我得到了

ImportError: 没有名为 twisted.internet 的模块。

我还注意到,在 git 的 README.rst 中,它没有提到模块 twisted.internet。

那么我应该去哪里买呢?

【问题讨论】:

  • 你试过pip install Twisted吗?

标签: python installation pip twisted


【解决方案1】:

永远不要sudo pip install ... 任何东西。请改用virtualenv

exarkun@baryon:~$ virtualenv /tmp/virtualenv-demo
Running virtualenv with interpreter /usr/bin/python2
New python executable in /tmp/virtualenv-demo/bin/python2
Also creating executable in /tmp/virtualenv-demo/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
exarkun@baryon:~$ . /tmp/virtualenv-demo/bin/activate
(virtualenv-demo) exarkun@baryon:~$ pip install twisted
Collecting twisted
Collecting constantly>=15.1 (from twisted)
  Using cached constantly-15.1.0-py2.py3-none-any.whl
Collecting zope.interface>=3.6.0 (from twisted)
Collecting Automat>=0.3.0 (from twisted)
  Using cached Automat-0.5.0-py2.py3-none-any.whl
Collecting incremental>=16.10.1 (from twisted)
  Using cached incremental-16.10.1-py2.py3-none-any.whl
Requirement already satisfied: setuptools in /tmp/virtualenv-demo/lib/python2.7/site-packages (from zope.interface>=3.6.0->twisted)
Collecting attrs (from Automat>=0.3.0->twisted)
  Using cached attrs-16.3.0-py2.py3-none-any.whl
Requirement already satisfied: six in /tmp/virtualenv-demo/lib/python2.7/site-packages (from Automat>=0.3.0->twisted)
Requirement already satisfied: appdirs>=1.4.0 in /tmp/virtualenv-demo/lib/python2.7/site-packages (from setuptools->zope.interface>=3.6.0->twisted)
Requirement already satisfied: packaging>=16.8 in /tmp/virtualenv-demo/lib/python2.7/site-packages (from setuptools->zope.interface>=3.6.0->twisted)
Requirement already satisfied: pyparsing in /tmp/virtualenv-demo/lib/python2.7/site-packages (from packaging>=16.8->setuptools->zope.interface>=3.6.0->twisted)
Installing collected packages: constantly, zope.interface, attrs, Automat, incremental, twisted
Successfully installed Automat-0.5.0 attrs-16.3.0 constantly-15.1.0 incremental-16.10.1 twisted-17.1.0 zope.interface-4.3.3
(virtualenv-demo) exarkun@baryon:~$ python -c 'import twisted.internet; print twisted.internet'
<module 'twisted.internet' from '/tmp/virtualenv-demo/local/lib/python2.7/site-packages/twisted/internet/__init__.pyc'>
(virtualenv-demo) exarkun@baryon:~$ deactivate 
exarkun@baryon:~$ 

【讨论】:

  • 感谢您的帮助。但是当我输入命令 python -c 'import twisted.internet; print twisted.internet',我得到 File "", line 1 import twisted.internet;打印 twisted.internet ^ SyntaxError: invalid syntax
  • 也许您使用的是 Python 3,并且您必须使用 print 作为函数而不是语句。 python -c ... 行只是证明 Twisted 已正确安装。您没有必须执行该步骤。您可以尝试运行您拥有的任何基于 Twisted 的代码(确保使用来自 virtualenv 的 Python 可执行文件 - 它会在您的 $PATH 中,因此它应该可以工作 - 只是不要硬编码 /usr/bin/python 或任何地方都有类似的东西)。
猜你喜欢
  • 2013-01-19
  • 2011-06-11
  • 2012-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多