原文:
socket服务器可通过来搭建
在终端输入命名:python chatserver.py
看到提示:Iphone Chat server started表示创建成功.
但是有的时候看到的提示是: No module named twisted.internet.protocol:表示本机上没有安装twisted,需要自己安装.下载地址.
ope.interface/twisted官网下载地址:
ope.interface/twisted 百度网盘下载地址:
链接: 密码: rr13步骤如下:
1.苹果电脑一般都安装了,在终端,输“which python”或“which python3”,会显示python的安装目录。2.先安装zope.interface,才能安装twisted.
安装方法:下载gz压缩包,解压后,会看到有个”setup.py” 文件,在终端下,输入“python setup.py install”或“python3 setup.py install”.便可以安装zope.interface。 如果出现error: can't create or remove files in install directory The following error occurred while trying to add or remove files in the installation directory: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/ test-easy-install-411.write-test' The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was: /Library/Python/2.7/site-packages/ **Perhaps your account does not have write access to this directory?** If the installation directory is a system-owned directory, you may need to sign in as the administrator or "root" account. If you do not have administrative access to this machine, you may wish to choose a different installation directory, preferably one that is listed in your PYTHONPATH environment variable. For information on other options, you may wish to consult the documentation at: http://peak.telecommunity.com/EasyInstall.html Please make the appropriate changes for your system and try again.
这一段错误,因为python路径是在系统路径下,默认不能写.(报错的原因就是因为权限不够)
解决方案:使用命令sudo python setup.py install
3.检查下MAC有没有自带twisted。
检查方法:打开python命令行,输入“import twisted”,如果没有任何提示,说明你已经有twisted了,若提示没有”twisted”模块,则需要自己安装twisted。 安装方法:参考zope.interface的安装,(如果权限不够,同样在命令之前加上sudo),安装完成之后再用”import twisted”一下 出现下图表示通过 之后就可以用命令,开启服务了python chatserver.py