Windows10下SQLCipher编译完成后,PyCharm中配置使用问题求助
解决Windows10下PyCharm中安装pysqlcipher3失败的问题
前置背景
已从GitHub下载sqlcipher-master并在Windows10上完成编译,命令行可正常运行sqlite3.exe:
C:\Users\pcc\Desktop\sqlcipher-master\sqlcipher-master>sqlite3.exe
返回信息:
SQLite version 3.42.0 2023-05-16 12:36:15 (SQLCipher 4.5.5 community) Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite>
尝试在PyCharm Community 2021.3.2的Python项目中用pysqlcipher3替代命令行操作,执行pip3 install pysqlcipher3时出现错误:
Failed to build pysqlcipher3 ERROR: Could not build wheels for pysqlcipher3, which is required to install pyproject.toml-based projects
解决步骤
1. 安装编译依赖
Windows下编译pysqlcipher3需要Visual Studio Build Tools,必须安装以下组件:
- MSVC v142及以上版本的生成工具
- 对应Windows10版本的Windows SDK
2. 指定本地SQLCipher路径安装
利用已编译好的SQLCipher,在安装时明确指定头文件和库文件路径,执行以下命令:
pip install pysqlcipher3 --global-option=build_ext --global-option="-IC:\Users\pcc\Desktop\sqlcipher-master\sqlcipher-master\include" --global-option="-LC:\Users\pcc\Desktop\sqlcipher-master\sqlcipher-master\lib" --global-option="-lsqlcipher"
- 注意替换路径为你实际编译后SQLCipher的
include和lib目录(若编译输出在build等子文件夹,需对应调整) - 若编译生成的库文件名不是
sqlcipher.lib,需修改-lsqlcipher为实际文件名
3. 验证安装有效性
在Python项目中运行以下测试代码,确认无报错即可:
import pysqlcipher3.dbapi2 as sqlite3 # 连接加密数据库 conn = sqlite3.connect('encrypted.db') cursor = conn.cursor() # 设置加密密钥 cursor.execute("PRAGMA key='your_secure_password'") # 执行测试操作 cursor.execute('CREATE TABLE IF NOT EXISTS demo (id INTEGER PRIMARY KEY)') cursor.execute("INSERT INTO demo VALUES (1)") conn.commit() conn.close()
4. 预编译wheel替代方案
若上述编译方式仍失败,可下载对应Python版本、系统架构的pysqlcipher3预编译wheel文件,本地安装:
pip install path/to/your/downloaded/pysqlcipher3-xxx.whl
内容的提问来源于stack exchange,提问作者the flow
相关产品推荐
相关产品推荐

