Deployment fail - no module named replit


My repl ( is currently deployed but a few days ago it stopped being able to re-deploy so I cannot update it.

The error is "No module named ‘replit’ "

I can see and use replit db from the development environment. The deployment environment apparently cannot see it.

Also, interestingly, when I run python scripts from the shell, they cannot see it, which is a weird problem, but not the central problem here. See below for example.

I have tried forking to a new replit, uninstalling and reinstalling the replit module from the package manager, and manually using pip and poetry to install replit from the shell but these have no impact.

Deployment Log:

01/08/24 09:57:03 PM
WARNING:waitress.queue:Task queue depth is 2
01/08/24 09:57:03 PM
WARNING:waitress.queue:Task queue depth is 1
01/08/24 09:22:05 AM
WARNING:waitress.queue:Task queue depth is 1
01/08/24 08:49:46 AM
hostingpid1: an open port was not detected
01/08/24 08:48:49 AM
Website status: UP
01/08/24 08:48:49 AM
01/08/24 08:48:47 AM
Traceback (most recent call last):
01/08/24 08:48:47 AM
File "/home/runner/16b197b3-3108-47b8-903b-7f5efdf88f58/src/", line 17, in <module>
01/08/24 08:48:47 AM
from replit import db
01/08/24 08:48:47 AM
ModuleNotFoundError: No module named 'replit'
01/08/24 08:48:47 AM
Loading Modules..
01/08/24 08:48:46 AM
01/08/24 08:48:46 AM
01/08/24 08:48:45 AM
starting up user application

Other relevant information:

The following script won’t run from the shell, but if I paste its code into and press ‘Run’, it works.

~/MAIN-LL$ cat src/
from replit import db

if 'log' in db:
  print(f'Log found, {len(db["log"])} lines.')
  print('db["log"] not found.')
~/MAIN-LL$ python3 src/ 
Traceback (most recent call last):
  File "/home/runner/MAIN-LL/src/", line 1, in <module>
    from replit import db
ModuleNotFoundError: No module named 'replit'
~/MAIN-LL$ poetry add replit
The following packages are already present in the pyproject.toml and will be skipped:

  • replit

If you want to update it to the latest compatible version, you can use `poetry update package`.
If you prefer to upgrade it to the latest available version, you can use `poetry add package@latest`.

Nothing to add.
~/MAIN-LL$ pip install replit
Collecting replit
  Downloading replit-3.5.0-py3-none-any.whl (34 kB)
Collecting Werkzeug<4,>=2
  Downloading werkzeug-3.0.1-py3-none-any.whl (226 kB)
     |████████████████████████████████| 226 kB 2.5 MB/s 
Collecting aiohttp<4.0.0,>=3.6.2
  Downloading aiohttp-3.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB)
     |████████████████████████████████| 1.2 MB 21.9 MB/s 
Collecting Flask<3.0.0,>=2.0.0
  Downloading flask-2.3.3-py3-none-any.whl (96 kB)
     |████████████████████████████████| 96 kB 45.0 MB/s 
Collecting pyseto<2.0.0,>=1.6.11
  Downloading pyseto-1.7.7-py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 46.1 MB/s 
Collecting typing_extensions<5,>=4
  Downloading typing_extensions-4.9.0-py3-none-any.whl (32 kB)
Collecting urllib3==1.26.18
  Downloading urllib3-1.26.18-py2.py3-none-any.whl (143 kB)
     |████████████████████████████████| 143 kB 62.3 MB/s 
Collecting protobuf<5.0.0,>=4.21.8
  Downloading protobuf-4.25.1-cp37-abi3-manylinux2014_x86_64.whl (294 kB)
     |████████████████████████████████| 294 kB 82.6 MB/s 
Collecting requests<3.0.0,>=2.25.1
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     |████████████████████████████████| 62 kB 26.2 MB/s 
Collecting aiohttp-retry<3.0.0,>=2.8.3
  Downloading aiohttp_retry-2.8.3-py3-none-any.whl (9.8 kB)
Collecting yarl<2.0,>=1.0
  Downloading yarl-1.9.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (301 kB)
     |████████████████████████████████| 301 kB 48.1 MB/s 
Collecting async-timeout<5.0,>=4.0
  Downloading async_timeout-4.0.3-py3-none-any.whl (5.7 kB)
Collecting multidict<7.0,>=4.5
  Downloading multidict-6.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114 kB)
     |████████████████████████████████| 114 kB 52.5 MB/s 
Collecting frozenlist>=1.1.1
  Downloading frozenlist-1.4.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239 kB)
     |████████████████████████████████| 239 kB 66.9 MB/s 
Collecting attrs>=17.3.0
  Downloading attrs-23.2.0-py3-none-any.whl (60 kB)
     |████████████████████████████████| 60 kB 39.8 MB/s 
Collecting aiosignal>=1.1.2
  Downloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)
Collecting Jinja2>=3.1.2
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     |████████████████████████████████| 133 kB 37.4 MB/s 
Collecting click>=8.1.3
  Downloading click-8.1.7-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 52.8 MB/s 
Collecting itsdangerous>=2.1.2
  Downloading itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting blinker>=1.6.2
  Downloading blinker-1.7.0-py3-none-any.whl (13 kB)
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Collecting iso8601<3.0.0,>=1.0.2
  Downloading iso8601-2.1.0-py3-none-any.whl (7.5 kB)
Collecting cryptography<42,>=41.0.5
  Downloading cryptography-41.0.7-cp37-abi3-manylinux_2_28_x86_64.whl (4.4 MB)
     |████████████████████████████████| 4.4 MB 77.5 MB/s 
Collecting argon2-cffi<24.0.0,>=23.1.0
  Downloading argon2_cffi-23.1.0-py3-none-any.whl (15 kB)
Collecting pycryptodomex<4.0.0,>=3.18.0
  Downloading pycryptodomex-3.19.1-cp35-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 49.4 MB/s 
Collecting argon2-cffi-bindings
  Downloading argon2_cffi_bindings-21.2.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (86 kB)
     |████████████████████████████████| 86 kB 63.1 MB/s 
Collecting cffi>=1.12
  Downloading cffi-1.16.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (443 kB)
     |████████████████████████████████| 443 kB 67.6 MB/s 
Collecting pycparser
  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
     |████████████████████████████████| 118 kB 63.8 MB/s 
Collecting certifi>=2017.4.17
  Downloading certifi-2023.11.17-py3-none-any.whl (162 kB)
     |████████████████████████████████| 162 kB 78.2 MB/s 
Collecting idna<4,>=2.5
  Downloading idna-3.6-py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 7.3 MB/s 
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)
     |████████████████████████████████| 142 kB 51.4 MB/s 
Installing collected packages: pycparser, multidict, idna, frozenlist, cffi, yarl, MarkupSafe, attrs, async-timeout, argon2-cffi-bindings, aiosignal, Werkzeug, urllib3, pycryptodomex, Jinja2, itsdangerous, iso8601, cryptography, click, charset-normalizer, certifi, blinker, argon2-cffi, aiohttp, typing-extensions, requests, pyseto, protobuf, Flask, aiohttp-retry, replit
Successfully installed Flask-2.3.3 Jinja2-3.1.2 MarkupSafe-2.1.3 Werkzeug-3.0.1 aiohttp-3.9.1 aiohttp-retry-2.8.3 aiosignal-1.3.1 argon2-cffi-23.1.0 argon2-cffi-bindings-21.2.0 async-timeout-4.0.3 attrs-23.2.0 blinker-1.7.0 certifi-2023.11.17 cffi-1.16.0 charset-normalizer-3.3.2 click-8.1.7 cryptography-41.0.7 frozenlist-1.4.1 idna-3.6 iso8601-2.1.0 itsdangerous-2.1.2 multidict-6.0.4 protobuf-4.25.1 pycparser-2.21 pycryptodomex-3.19.1 pyseto-1.7.7 replit-3.5.0 requests-2.31.0 typing-extensions-4.9.0 urllib3-1.26.18 yarl-1.9.4
~/MAIN-LL$ python3 src/ 
Traceback (most recent call last):
  File "/home/runner/MAIN-LL/src/", line 1, in <module>
    from replit import db
ModuleNotFoundError: No module named 'replit'

Thanks for any help!

Check your replit.nix file.

{ pkgs }: {
  deps = [

First of all, the pyflakes package is 311 instead of 310… not sure if makes any difference though so it should be fine.
However, any installed nix package in the category of python311Packages or python310Packages has a problem on replit where PYTHONPATH environment variable is “corrupted” or overwritten (sometimes).
This will cause your program to not be able to import the normal python packages (in .pythonlibs/lib/python3.10/site-packages), even though they are installed.
(This bug has not been reported but I will create a bug report on it soon I think.)

There are two fixes possible:

  1. Remove the System dependency nix package. (Most of the time you can install it as a python package instead, using Packages tool, and it will work.)
  2. Manually edit PYTHONPATH to be correct. The best way to do this is shown below:

Show hidden files, and open .replit file. Near the end, add:

PYTHONPATH = "$REPL_HOME/.pythonlibs/lib/python3.10/site-packages:$PYTHONPATH"

(Depending on the situation, sometimes the path has to be at the end instead of at the front, but probably not here.)

Any time there are unexpected ModuleNotFoundErrors, check PYTHONPATH or sys.path

1 Like

That fixed it, thanks!!

That’s great.
Please mark my post as solution in case others have a similar problem.
Also, it would be nice if you clarified which fix you used, but I’m assuming it would be the 2nd fix (fixing PYTHONPATH).

It was adding the [env] and PYTHONPATH lines to .replit that fixed it. It deploys properly now, and python scripts run from the command line can see all my installed packages again, including replit db.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.