简体   繁体   English

ImportError:没有名为'twisted'的模块

[英]ImportError: No module named 'twisted'

I'm new to python and I'm writing a simple TCP server Server.py , and I'm trying to import the reactor using this line of code from twisted.internet import reactor The problem is when I run the code I get this error 我是python的新手,我正在编写一个简单的TCP服务器Server.py ,我正在尝试使用from twisted.internet import reactor的这行代码from twisted.internet import reactor问题是当我运行代码时我得到了这个错误

/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5     /Users/Nora/PycharmProjects/Server/Server.py
Traceback (most recent call last):
  File "/Users/Nora/PycharmProjects/Server/Server.py", line 2, in <module>
    from twisted.internet import reactor
ImportError: No module named 'twisted'

Note that I am using OS X Yosemite, and I have installed a new python version 3.5, how can I go back to the system built in version which already has twisted? 请注意,我使用的是OS X Yosemite,我已经安装了一个新的python版本3.5,我怎样才能回到已经扭曲的版本内置的系统?

As xiaohen commented, twisted isn't in the standard python lib (It is installed on the internal OS X python by apple, but it won't automatically be available if you install a newer version of python). 正如xiaohen所评论的那样,twisted不在标准的python lib中(它由apple安装在内部OS X python上,但是如果你安装了更新版本的python,它将无法自动使用)。

pip install twisted will likely get you there. pip install twisted可能会让你在那里。

BTW you might want to read and install the python virtualenv system before you install twisted so you'll know you can muck with your python libraries without having to worry about corrupting your core python load (Guides like http://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/ or http://michaelheap.com/virtualenv-and-pip-a-python-environment-in-60-seconds/ will help) 顺便说一句,你可能想要在安装twis​​ted之前阅读并安装python virtualenv系统,这样你就会知道你可以搞砸你的python库而不必担心破坏你的核心python负载(像http://www.dabapps.com这样的指南) / blog / introduction-to-pip-and-virtualenv-python /http://michaelheap.com/virtualenv-and-pip-a-python-environment-in-60-seconds/会有帮助)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM