标题: 在鸿蒙PC上安装python native扩展包
时间: 13小时前发布,4小时前修改
推荐使用基于 Harmonybrew 的方案,不需要编译,安装更快,兼容性可能也更好(可以避免编译失败)。
操作步骤:
1.打开开发者模式(提供HiShell终端)。
2.打开 https://harmonybrew.atomgit.com/ 查看Harmonybrew安装步骤。
3.打开 https://atomgit.com/Harmonybrew/docs/blob/main/zh-CN/user/featured-packages.md
查看“场景三:安装 Python 三方库”安装步骤。
以下是基于 DevBox 的方案:
打开开发者模式(提供HiShell终端)。
从应用商店安装Python安装器(提供python3命令):
从应用商店安装DevBox(提供clang和clang++命令):
打开HiShell终端,首先执行
export CC=clang CXX=clang++
指定要使用clang和clang++作为原生C/C++编译器,然后执行
python3 -m pip install aiohttp
(把aiohttp换成你想安装的包)
就能正常安装大部分适配Linux的原生库了。
有些库可能会因为使用了gcc特定语法或依赖特定Linux发行版的功能导致编译失败,不过常用的可移植性做得好的原生库应该都能编译成功。
echo 'export CC=clang CXX=clang++' >> ~/.zshrc
首先运行
python3 -m pip install --upgrade pip
把新版pip命令安装到 ~/.local/bin 目录,
然后在 ~/.zshrc 中新增 export PATH=~/.local/bin:$PATH 即可实现直接运行pip命令(执行以下命令后重启终端生效):
echo 'export PATH=~/.local/bin:$PATH' >> ~/.zshrc
通过pip安装的其他命令也可以通过这种方式直接调用。
比如这种报错:
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host www.baidu.com:443 ssl:True [SSLCertVerificationError: (1, '【SSL: CERTIFICATE_VERIFY_FAILED】 certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')])
python3 -m pip install --upgrade certifi
export SSL_CERT_FILE=$(python3 -c 'import certifi; print(certifi.where())')
echo "export SSL_CERT_FILE=$(python3 -c 'import certifi; print(certifi.where())')" >> ~/.zshrc
『回复列表(1|隐藏机器人聊天)』
比如这种报错:
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host www.baidu.com:443 ssl:True [SSLCertVerificationError: (1, '【SSL: CERTIFICATE_VERIFY_FAILED】 certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')])
python3 -m pip install --upgrade certifi
export SSL_CERT_FILE=$(python3 -c 'import certifi; print(certifi.where())')
echo "export SSL_CERT_FILE=$(python3 -c 'import certifi; print(certifi.where())')" >> ~/.zshrc