Repository: praw-dev/praw

Issue:
SQLite Import Error on 7.3.0
I'm now getting a 
`ModuleNotFoundError: No module named '_sqlite3'`
error right upon import. Is there a way to catch this?




Discussion:
What's your environment? 
Ubuntu 20 LTS, Python 3.8.8
That's fascinating. The fix is to install `sudo apt-get install libsqlite3-dev`, but I'm a little confused why that's necessary because sqlite3 is part of python's standard library. I suppose we can move the import to inside the class so that it only affects people who try to use it.
Production would be on App Engine Flex Env (Again 3.8) — Haven't had a chance to test it out yet.
This issue is stale because it has been open for 20 days with no activity. Remove the Stale label or comment or this will be closed in 10 days.
I'm assuming this is a result of the new SQLite token manager in 7.3.0.

> I'm a little confused why that's necessary because sqlite3 is part of python's standard library. 

Some Python stdlib modules are not guaranteed to be built and available on all platforms because they rely on external, non-Python dependencies, as is the case for sqlite. These are commonly bundled with most Python distributions on macOS and Windows, but if a distro or integrator-packaged Python on Linux, it will often be a separate distro package that may or may not be installed by default, especially on lightweight/minimal Linux installs.

> I suppose we can move the import to inside the class so that it only affects people who try to use it.

This is [a not-uncommon occurance](https://www.google.com/search?q=ModuleNotFoundError%3A+No+module+named+%27_sqlite3%27&ie=utf-8&oe=utf-8), so it would make sense to guard the import or import it in a scope that would only run when the class was used. Using `raise from` to wrap it in a friendlier error message and/or printing a short description of how to solve the issue (whatever follows your current convention for handling user-facing errors) would seem to be a good idea from a UX perspective and avoid extra future issue load.
This issue is stale because it has been open for 20 days with no activity. Remove the Stale label or comment or this will be closed in 10 days.
This issue was closed because it has been stale for 10 days with no activity.
Presumably this is now moot; I assume given the token managers are deprecated, the relevant imports will be removed when they are (in 8.0, I'd assume)?
Yeah, these managers need to be removed.
This issue is stale because it has been open for 20 days with no activity. Remove the Stale label or comment or this will be closed in 10 days.
Bump

Resolving patch:
diff --git a/praw/util/token_manager.py b/praw/util/token_manager.py
--- a/praw/util/token_manager.py
+++ b/praw/util/token_manager.py
@@ -11,7 +11,6 @@
     Tokens managers have been depreciated and will be removed in the near future.
 
 """
-import sqlite3
 from abc import ABC, abstractmethod
 
 
@@ -121,6 +120,8 @@ def __init__(self, database, key):
 
         """
         super().__init__()
+        import sqlite3
+
         self._connection = sqlite3.connect(database)
         self._connection.execute(
             "CREATE TABLE IF NOT EXISTS tokens (id, refresh_token, updated_at)"


Test patch: