python - 相同的 python 解释器,但 json_set 仅不适用于 Visual Studio Code,适用于其他任何地方
问题描述
我无法绕过我的头。
完全相同的代码,完全相同的解释器,在其他任何地方都可以工作,但不能在Visual Studio Code
.
让我们考虑以下示例:
import sqlite3
_connection = sqlite3.connect(":memory:")
_connection.row_factory = sqlite3.Row
create_table = """
create table food (
id int not null,
data json not null,
primary key(id)
)
"""
insert = """
insert into food (id, data)
values (1, '{"name": "Steak"}')
"""
update = """
update food
set data = json_set(data, '$.name', 'Bacon and Eggs')
where id = 1
"""
fetch_query = "select json_extract(data, '$.name') as name from food where id = 1"
with _connection:
_connection.execute(create_table)
_connection.execute(insert)
_connection.execute(update)
food = _connection.execute(fetch_query)
new_food = dict(food.fetchone()).get('name')
print(new_food)
它应该打印出来Bacon and Eggs
但Visual Studio Code
抱怨json_set
不是一个功能。
如何检查内部sqlite3
使用的版本是什么Visual Studio Code
?不知道为什么从 vs 代码运行它与从外部终端运行它的行为不同。
更新 1
Linux 终端
更新 2
我不依赖 VS 代码来确定要使用哪个版本的 python。我正在明确输入它。估计和pip
我没关系。pip
反正我用的是同一个版本。
解决方案
谢谢吉尔和肖恩。
原来Visual Studio Code
是使用与sqlite3
系统不同的引擎盖下版本。
我只好pip install pysqlite3-binary
。
和
import pysqlite3 as sqlite3
...
其他一切都没有改变。
我很确定还有其他方法可以解决这个问题,但我就是这样做的。
推荐阅读
- r - ggplot2 geom_plot 值在同一个栏中
- node.js - 使用类似运算符 inito MongoDB 的节点 JS 休息服务
- python - Python 3 中的 Django 问题“super() argument 1 must be type, not WSGIRequest”
- android - 如何在对象列表中显示两个对象( Book 和 Feed_model )而不从 Firebase 实时数据库获取重复数据
- c# - C# WPF - 最大化应用程序时隐藏任务栏
- python - 将 2-dim 数组绘制为线图 python
- android - Jitpack:无法安装以下 Android SDK 包,因为某些许可证尚未被接受
- java - 使用 Java 在 Android 设备上合并多个 SQL 文件
- jquery - 选择另一个选项后如何使选择器开关工作?
- c++ - 如何正确调用 Assert::ExpectException?