socket服务器的搭建-Mac(转)

本文介绍如何在Mac上安装必要的Python库并搭建Socket服务器。包括解决安装zope.interface及twisted过程中遇到的权限问题,并验证安装是否成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文:http://m.blog.youkuaiyun.com/article/details?id=51126881

socket服务器可通过Python来搭建 
在终端输入命名:

python chatserver.py

看到提示:Iphone Chat server started表示创建成功. 
但是有的时候看到的提示是: 
No module named twisted.internet.protocol:表示本机上没有安装twisted,需要自己安装.

chatserver.py下载地址.

ope.interface/twisted官网下载地址: 
https://pypi.python.org/pypi/zope.interface 
https://twistedmatrix.com/trac/wiki/Downloads

ope.interface/twisted 百度网盘下载地址: 
链接: http://pan.baidu.com/s/1qYtcu6K 密码: rr13

步骤如下: 
1.苹果电脑一般都安装了python,在终端,输“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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值