The Python interpreter behaves consistently across different platforms, except for a specific issue with json_set in Visual Studio Code

I can't seem to understand what's going on.

The code works fine everywhere except in Visual Studio Code.

Take a look at this example:

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)

It should print out Bacon and Eggs but for some reason Visual Studio Code is giving an error saying json_set is not a function.

How can I check the version of sqlite3 being used internally by Visual Studio Code? I'm puzzled why it behaves differently inside vs outside the editor.

Update 1

Linux Terminal

https://i.stack.imgur.com/5j5fg.png

Visual Studio Code https://i.stack.imgur.com/VuEYB.png

Update 2

I'm specifying the Python version explicitly, it's not dependent on VS code to decide. No issues with pip either. Both images show the same version of pip being used.

Vs code https://i.stack.imgur.com/MUkak.png

Linux terminal https://i.stack.imgur.com/oRvYM.png

Answer №1

Appreciate the help, Jill and Shawn.

It turns out that Visual Studio Code uses a different version of sqlite3 than what is installed on the system.

All I needed to do was run pip install pysqlite3-binary.

Also,

import pysqlite3 as sqlite3
...

Nothing else needed to be changed.

I'm confident there are alternate solutions to this issue, but this method worked for me.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to perform a query selection in WordPress

I need to accomplish this within 2 hours. I have custom fields stored in the database and I am trying to retrieve post IDs based on the meta keys or values. Here is what I have so far: $post_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta W ...

Getting text from a dropdown menu using selenium

Is there a way to extract text from a dropdown using Selenium and store it as a list? Here is the HTML code: <ul data-v-c71dad74="" data-dropdown-list="" class="list"><li data-v-c71dad74="" data-dropdown-ite ...

Issue encountered when including a date requirement in wpdb prepare

Can someone please help me understand how to properly add a conditional date in wpdb prepare? I'm having trouble with this code. Any insights? $results= $wpdb->get_results($wpdb->prepare('SELECT * FROM mytable WHERE date = DATE_FORMAT(%s, ...

Tips for terminating a loop once a randomly generated number reaches zero

I'm struggling with Python and cannot figure out a solution that makes sense to me. I'm attempting to have the program print "random timer has ended" once a random countdown is completed. import time from random import randint RandomTimer = ran ...

A guide on iterating through a JSON object fetched using Http in Angular 2/Typescript

I am attempting to extract specific data from my JSON file using http. The structure of the JSON is as follows: [{"name":"Name1","perc":33},{"name":"Name2","perc":22},{"name":"Name3","perc":41}] To loop through this retrieved object, I use the following ...

Having difficulty interpreting $ .ajax data within the controller

I am currently working on a jQuery .ajax project where the user interacts with a button in the view, triggering a $.ajax request. The goal is to send the user's name to a controller, which will then add "Hello" in front of the name and send back a JSO ...

efficient method for organizing subgraphs

Imagine a scenario where there are 6 elements labeled A, B, C, D, E, and F. Element A is connected to B (or vice versa without directionality), B is connected to C, D is connected to E, and F remains unconnected. However, the goal is not just to identify d ...

What is the best way to fetch images from a JSON object in a React application?

I have been trying to load images from an array of objects in React, but I keep encountering a "module not found" error. This issue has been frustrating me for the past couple of days. Can someone please help me troubleshoot this problem or provide some su ...

Append to an existing JSON file at a designated location

I am currently facing a task where I need to add specific values from one JSON file into another JSON file. However, the challenge is that I can append these values at the end of the destination JSON file but not at the exact specified location. The origin ...

Steps to resolve: Issue of TypeError - Expected 2 arguments for filter, received only 1

Currently, I am creating a browser using Python along with PyQt5/PySide6. One of the features I have implemented is an adblocker that utilizes a list to block ads from opening as tabs. ` class WebPage(QWebEnginePage): adblocker = filter(open(os.path. ...

Use pandas to generate a new dataframe by selecting a range of values from two columns

I have a dataframe structured like this, with the index containing the start_period and end_period. My goal is to transform the dataframe index into a range as shown below: | range_date | due_date | | ------------------ | -------- ...

Update: Explored 0 web pages (at a rate of 0 pages per minute) and obtained information from 0 elements (at a rate of

I'm a beginner in Python and Scrapy, currently working on my first project to crawl web security information from a website. However, when I try to run it using cmd, I encounter the message "Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 item ...

Tips for Displaying a Logo Animation at the Start of the Game

Could I display a logo before my game starts, similar to how the SEGA logo appears at the beginning of Sonic The Hedgehog? It would be awesome if this feature is possible! Thank you! ...

A step-by-step guide on setting up and launching an AWS Lambda function using Boto3 to work with a Node

I am currently in the process of uploading a NodeJS file to an s3 bucket, and now I need to execute the node.js files that have been uploaded to the s3 bucket. Below is my existing code snippet: s3=boto3.client('s3', zone,aws_access_key_id=aws_ac ...

An issue has arisen with MQTT on the Raspberry Pi involving SSL: [UNSUPPORTED_PROTOCOL] indicating that an unsupported protocol is being used (_ssl.c

An issue has arisen with my MQTT broker running on an AWS server. While it operates correctly on Mac and Windows devices, it does not function as expected on my Raspberry Pi. The subscriber and publisher code have been tested on various operating systems, ...

Is there a way to eliminate specific lines from a JSON file that share a common pattern?

Hey, I have a json file containing 5000 lines where some of them follow a pattern similar to this: [ {"a":"c", "b":"e", "i":"a"}, {"a":"c", "b":"/", "i":"a"}, {"a":"c", "b":"/", "i":"a"}, {"a":"c", "b":"e/esa", "i":"a"}, {"a":"i", "b":"a/e/", "i":"ah"}, ] ...

Challenges with handling JSON data in JavaScript

I am currently attempting to retrieve and parse JSON data in order to display it on a blank HTML file. Unfortunately, I keep encountering an issue where if I retrieve and parse the data, I receive an error stating Uncaught TypeError: Cannot read property & ...

Updating JSON in JavaScript

I am striving to structure a JSON object in the following manner: {"tokenId":1,"uri":"ipfs://bafy...","minPrice":{"type":"BigNumber","hex":"0x1a"},"signature":"0 ...

What steps should I take to extract the rendered title from this JSON data?

After trying to access the title using json["title"]["rendered"].string!, I noticed that all I was receiving was nil. [ { "title":{ "rendered":"Nachhilfe für mehrere Hauptfächer" }, "comment_status":"open", "p ...

JSON-formatted public data sets

Can anyone point me towards a public dataset in Json format? Ideally, I am searching for one that falls within the 10-20GB range. The larger datasets I've come across so far have all been in XML format. ...