Termux 用 pip 安装出现 'crypt.h' file not found 解决方法

在Termux环境中搭建私人博客,使用pip安装特定库时遇到'crypt.h'文件未找到的问题。为了解决这个问题,可以尝试安装相关依赖。参照GitHub上的相关issue讨论,如theimpostor/termux-vim-ycm和termux/termux-packages的issue,可能的解决方法是安装缺失的依赖包。

问题

在 Termux 上搭私人博客时,使用 pip 安装依赖,安装一些库比如 Pillowcffi 时出现如下图错误:
这里写图片描述

   In file included from src/_imaging.c:74:
    /data/data/com.termux/files/usr/include/python3.6m/Python.h:39:10: fatal error: 'crypt.h' file not found
    #include <crypt.h>
             ^~~~~~~~~
    1 error generated.
    error: command 'arm-linux-androideabi-clang' failed with exit status 1

解决办法

安装 libcrypt-dev,具体如下:

pkg install libcrypt-dev

参考资料:
https://github.com/theimpostor/termux-vim-ycm/issues/1
https://github.com/termux/termux-packages/issues/1142
https://github.com/termux/termux-packages/issues/1964

Building wheel for mysqlclient (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for mysqlclient (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [81 lines of output] C:\Users\31082\AppData\Local\Temp\pip-build-env-vyx8bkpv\overlay\Lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:82: SetuptoolsDeprecationWarning: `project.license` as a TOML table is deprecated !! ******************************************************************************** Please use a simple string containing a SPDX expression for `project.license`. You can also use `project.license-files`. (Both options available on setuptools>=77.0.0). By 2026-Feb-18, you need to update your project and remove deprecated calls or your builds will no longer be supported. See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! corresp(dist, value, root_dir) C:\Users\31082\AppData\Local\Temp\pip-build-env-vyx8bkpv\overlay\Lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:61: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+) See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! dist._finalize_license_expression() C:\Users\31082\AppData\Local\Temp\pip-build-env-vyx8bkpv\overlay\Lib\site-packages\setuptools\dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+) See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! self._finalize_license_expression() # Options for building extension module: library_dirs: ['C:/mariadb-connector\\lib\\mariadb', 'C:/mariadb-connector\\lib'] libraries: ['kernel32', 'advapi32', 'wsock32', 'shlwapi', 'Ws2_32', 'crypt32', 'secur32', 'bcrypt', 'mariadbclient'] extra_link_args: ['/MANIFEST'] include_dirs: ['C:/mariadb-connector\\include\\mariadb', 'C:/mariadb-connector\\include\\mysql', 'C:/mariadb-connector\\include'] extra_objects: [] define_macros: [('version_info', (2, 2, 7, 'final', 0)), ('__version__', '2.2.7')] running bdist_wheel running build running build_py creating build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\connections.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\converters.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\cursors.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\release.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\times.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\_exceptions.py -> build\lib.win-amd64-cpython-314\MySQLdb copying src\MySQLdb\__init__.py -> build\lib.win-amd64-cpython-314\MySQLdb creating build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\CR.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\ER.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\FLAG.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants copying src\MySQLdb\constants\__init__.py -> build\lib.win-amd64-cpython-314\MySQLdb\constants running egg_info writing src\mysqlclient.egg-info\PKG-INFO writing dependency_links to src\mysqlclient.egg-info\dependency_links.txt writing top-level names to src\mysqlclient.egg-info\top_level.txt reading manifest file 'src\mysqlclient.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' adding license file 'LICENSE' writing manifest file 'src\mysqlclient.egg-info\SOURCES.txt' copying src\MySQLdb\_mysql.c -> build\lib.win-amd64-cpython-314\MySQLdb running build_ext building 'MySQLdb._mysql' extension creating build\temp.win-amd64-cpython-314\Release\src\MySQLdb D:\VisualStudio\VC\Tools\MSVC\14.44.35207\bin\HostX86\x64\cl.exe /c /nologo /O2 /W3 /GL /DNDEBUG /MD "-Dversion_info=(2, 2, 7, 'final', 0)" -D__version__=2.2.7 -IC:/mariadb-connector\include\mariadb -IC:/mariadb-connector\include\mysql -IC:/mariadb-connector\include -ID:\python\include -ID:\python\Include -ID:\VisualStudio\VC\Tools\MSVC\14.44.35207\include -ID:\VisualStudio\VC\Tools\MSVC\14.44.35207\ATLMFC\include -ID:\VisualStudio\VC\Auxiliary\VS\include "-ID:\Windows Kits\10\include\10.0.26100.0\ucrt" "-ID:\Windows Kits\10\\include\10.0.26100.0\\um" "-ID:\Windows Kits\10\\include\10.0.26100.0\\shared" "-ID:\Windows Kits\10\\include\10.0.26100.0\\winrt" "-ID:\Windows Kits\10\\include\10.0.26100.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tcsrc/MySQLdb/_mysql.c /Fobuild\temp.win-amd64-cpython-314\Release\src\MySQLdb\_mysql.obj _mysql.c src/MySQLdb/_mysql.c(29): fatal error C1083: 无法打开包括文件: “mysql.h”: No such file or directory error: command 'D:\\VisualStudio\\VC\\Tools\\MSVC\\14.44.35207\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for mysqlclient Failed to build mysqlclient error: failed-wheel-build-for-install × Failed to build installable wheels for some pyproject.toml based projects ╰─> mysqlclient
最新发布
11-20
<think>我们正在Termux环境下安装datasets库。 根据Termux环境的特点,我们需要确保Python环境已更新,然后使用pip安装。 从引用[1]中我们可以看到Termux安装Python和升级pip的命令: pkg install -y python3 python3-dev python3-pip pip install --upgrade pip setuptools wheel 安装datasets库可以直接使用pip命令,但考虑到Termux环境可能存在的网络问题,建议使用国内镜像源加速。 例如,使用清华镜像源:pip install datasets -i https://pypi.tuna.tsinghua.edu.cn/simple 因此,在Termux安装datasets的步骤如下: 1. 更新环境(如果已经安装过Python,可以跳过) 2. 使用pip安装datasets,推荐使用国内镜像源 注意:由于Termux是Android上的Linux环境,安装过程中可能会遇到一些依赖问题,比如需要安装一些编译工具。如果遇到,可以按需安装。 具体步骤: 步骤1:更新包列表并安装必要的工具(如果尚未安装) pkg update pkg install -y python3 python3-dev python3-pip clang make libffi-dev openssl-dev 步骤2:升级pip和setuptools pip install --upgrade pip setuptools wheel 步骤3:使用清华镜像源安装datasets pip install datasets -i https://pypi.tuna.tsinghua.edu.cn/simple 如果安装过程中出现编译错误,可能需要安装其他依赖,可以根据错误提示安装相应的包。 验证安装: 在Python交互环境中导入datasets库,如果没有报错则安装成功。 python >>> from datasets import load_dataset >>> print(load_dataset('squad', split='train')) 注意:在Termux安装大型库可能会遇到内存不足的问题,可以考虑使用交换分区(swap)来扩展内存。 §§相关问题§§ 1.Termux安装datasets库需要哪些依赖? 2. 如何解决Termux安装库时的内存不足问题? 3.Termux中如何使用其他镜像源安装datasets库? </think>在 Termux 环境中使用 pip 安装 `datasets` 库的完整步骤如下: ### 📌 安装步骤 1. **更新 Termux 环境** 确保系统包管理器和 Python 环境最新: ```bash pkg update && pkg upgrade pkg install -y python3 python3-dev python3-pip pip install --upgrade pip setuptools wheel ``` [^1] 2. **安装编译依赖** `datasets` 需要编译原生扩展,安装必要工具链: ```bash pkg install -y clang make libffi-dev openssl-dev export LDFLAGS="-L/data/data/com.termux/files/usr/lib" export CFLAGS="-I/data/data/com.termux/files/usr/include" ``` 3. **使用清华镜像安装 datasets** 避免网络超时,加速下载: ```bash pip install datasets \ -i https://pypi.tuna.tsinghua.edu.cn/simple \ --extra-index-url https://pypi.org/simple ``` 4. **验证安装** 运行 Python 解释器测试导入: ```bash python3 -c "from datasets import load_dataset; print(load_dataset('squad', split='train'))" ``` ✅ 成功输出示例: ``` Dataset({ features: ['id', 'title', 'context', 'question', 'answers'], num_rows: 87599 }) ``` ### ️ 注意事项 1. **内存问题处理** Termux 内存限制可能导致编译失败: - 安装 `termux-api` 启用交换文件: ```bash pkg install termux-api termux-setup-storage ``` - 或手动创建交换分区: ```bash fallocate -l 2G /swapfile mkswap /swapfile swapon /swapfile ``` 2. **常见错误解决** - **依赖缺失错误**:根据提示安装缺失包,如 `pkg install libjpeg-turbo` - **版本冲突**:尝试指定版本 `pip install datasets==2.10.1` - **权限问题**:添加 `--user` 参数用户级安装 ### 🔍 验证安装成功 执行以下检查: ```bash # 检查库版本 pip show datasets | grep Version # 运行简易测试 python3 -c "from datasets import get_dataset_config_names; print(get_dataset_config_names('squad'))" ``` 预期输出: ``` ['plain_text', 'synthetic', ...] ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值