MuscleHub Project - Cannot run "sql_query"

I am stuck at the very beginning of the MuscleHub project. I have downloaded the files and opened the Jupyter Notebook for instructions. The only code I’ve run so far is:

from codecademySQL import sql_query

sql_query(’’’
SELECT *
FROM visits
LIMIT 5
‘’’)

When I run it, I get the following error: PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: ‘example.db’

Please help! This isn’t covered in the instructions. Thank you!

so kill the other process?
or use another file

if jupyter is keeping the file open then run your code without jupyter (is it doing anything useful anyway?)

The same error message pops up whether Jupyter is opened or closed. I haven’t opened ‘example.db’ at all, as far as I know.

You’d only get that error message if you’re trying to open it.

I suggest: copy your code to a text file and run it as you would otherwise. in other words, drop jupyter, it’s not doing anything for you anyway

and then if you can’t figure out which process you need to kill to release the file, rebooting (though overkill and silly) has the effect of killing all processes (obviously)

the reason you might not want to use jupyter (aside from it not being useful) is because it’s running python for you somewhere in the background which means that you have no control over when python starts/stops so you could for instance have an instance of python that has your file open and therefore you wouldn’t be able to open it again until the current one is closed

I rebooted and did nothing other than opening the text file and running the code. I got the same error message! I’m not sure what other process could be running this file. I even tried deleting the db file (‘example.db’) that was provided in the project files, and the same error message appears. Very strange.

I guess that promotes it to slightly more of a mystery.

I could look at the code if you want, but if that doesn’t reproduce the same thing on my end then I have a very hard time coming up with any more reasonable guesses with out being able to interact with the failure mode.

I downloaded the files from codecademy for the Musclehub capstone project at the end of the “Analyze Data with Python” course. In the same folder, I saved a text file with the following code, nothing else:

from codecademySQL import sql_query

sql_query(’’’
SELECT *
FROM visits
LIMIT 5
‘’’)

got a link to that?

ehh found it. after much random clicking around

Nope. Runs on my end.

what I did:
https://asciinema.org/a/oS9YpTSsnL1zmgRlUY6xcyCCk

Thanks, I appreciate your help. Something must be weird with my python setup or something. Oh well. This project doesn’t seem very critical.

Well, you could … NOT use the file.

Either change the filename in codecademySQL.py (though, it may very well fail in the same way)
or

comment this out so that it isn’t touching the file

# Clear example.db if it exists
# if os.path.exists('example.db'):
#     os.remove('example.db')

and change

conn = sqlite3.connect('example.db')

to

conn = sqlite3.connect(':memory:')

so that it runs in memory instead (which means it’ll be gone when you restart the program)

This seems to be working for me! Thanks, friend. I appreciate the time you took to help out a newbie.