python3.9在centos7 环境中pip安装报错:ModuleNotFoundError: No module named ‘_ctypes‘

python3.9在centos7 环境中pip安装报错:ModuleNotFoundError: No module named ‘_ctypes’

在这里插入图片描述
原因:python3.7以上版本需要一个新的依赖包libffi-devel,centos系统环境中缺乏这个包

解决:

yum info libffi-devel    #查看该包的信息
yum -y install libffi-devel   #安装包

然后到python安装目录下重新编译:

cd /usr/local/python3         #这是我的python3安装路径
make install     #编译

参考文章: Fanyi.baidu.com/?aldtype=16047#auto/zh.

如果你想将这个代码改为从英语翻译为多种语言,你可以修改以下部分: 1. 修改 `to` 参数:在 `from_data` 字典的 `'to'` 键的值,将其改为你想要翻译的目标语言的缩写。例如,如果你想将文本翻译为法语,你可以将 `'to': 'fr'`。 2. 修改结果处理部分:在 `try` 语句块,你可以根据需要对目标语言的翻译结果进行处理。 下面是修改后的代码示例,将文本从英语翻译为法语: ```python from urllib import request, parse import json from faker import Faker class trans(object): def __init__(self): self.url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule' def tran(self, text): index = text.find("http") text = text[:index] text = text.replace('\n', '').replace('#', '').replace('RT ', '').replace(':', '') ua = Faker().user_agent() headers = { 'User-Agent': ua, 'Host': 'fanyi.youdao.com', 'Origin': 'http://fanyi.youdao.com', 'Referer': 'http://fanyi.youdao.com/', } # 表单数据 from_data = { 'i': text, 'from': 'AUTO', 'to': 'fr', # 将目标语言改为法语('fr') 'smartresult': 'dict', 'client': 'fanyideskweb', 'doctype': 'json', 'version': '2.1', 'keyfrom': 'fanyi.web', 'action': 'FY_BY_REALTlME' } from_data = parse.urlencode(from_data).encode('utf-8') req = request.Request(self.url, from_data, headers) res = request.urlopen(req).read().decode("utf-8") target = json.loads(res) try: result = target['translateResult'][0][0]['tgt'] except: result = "Translate failed" return result if __name__ == '__main__': Obj = trans() text = "Speed limit 50 kph.\n#COVID19Africa #CoronavirusPandemic\n https://t…" res = Obj.tran(text) print(res) ``` 请注意,这只是将结果翻译为法语的示例,你可以根据需要修改 `'to'` 参数并处理翻译的结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值