No module named flask - deployment failing

Question:
i’m trying to deploy but keep getting a no module named ‘flask’ error in the deployment build. Flask is installed and I can see it in my .pythonlibs. Have tried multiple times uninstalling and reinstalling, but does not fix the issue.

Repl runs fine in browser.

Repl link/Link to where the bug appears:
Private repl: https://replit.com/@flixr/Flixr-Subtitles

Screenshots, links, or other helpful context:

Here are deployment logs:

2024-02-12T05:33:47Z info: Deployment: 1a4d6456-dc20-4caa-8800-dea42977b323
2024-02-12T05:33:47Z info: Build: fde17fee-570b-4a4e-99cf-b35f0b5736a8
2024-02-12T05:33:47Z info: Connecting to builder
2024-02-12T05:33:48Z info: Builder connected
2024-02-12T05:33:48Z info: Installing packages
--> poetry env list --full-path

2024-02-12T05:34:04Z info: Skipping Build as no Build command set
2024-02-12T05:34:04Z info: Pushing pid1 binary layer...
2024-02-12T05:34:05Z info: Created pid1 binary layer
2024-02-12T05:34:08Z info: Skipping Python layer creation
2024-02-12T05:34:08Z info: Skipping Node layer creation
2024-02-12T05:34:08Z info: Pushing hosting layer...
2024-02-12T05:34:08Z info: Pushing Repl layer...
2024-02-12T05:34:08Z info: Nix layers for this Repl are uncached.
2024-02-12T05:34:08Z info: Pushing nix-0 layer...
2024-02-12T05:34:09Z info: Created hosting layer
2024-02-12T05:34:54Z info: Created Repl layer
2024-02-12T05:35:44Z info: Created nix-0 layer
2024-02-12T05:35:44Z info: uploading image for cached layer
2024-02-12T05:35:44Z info: pushed cache image manifest
2024-02-12T05:35:45Z info: pushed cache soci index manifest
2024-02-12T05:35:45Z info: uploading cached layer
2024-02-12T05:35:45Z info: succesfully uploaded cached layer
2024-02-12T05:35:45Z info: Pushed image manifest
2024-02-12T05:35:45Z info: Pushed soci index manifest
2024-02-12T05:35:54Z info: Creating virtual machine
2024-02-12T05:36:04Z info: Virtual machine created
2024-02-12T05:36:04Z info: Waiting for deployment to be ready
2024-02-12T05:33:47Z info: Deployment: 1a4d6456-dc20-4caa-8800-dea42977b323
2024-02-12T05:33:47Z info: Build: fde17fee-570b-4a4e-99cf-b35f0b5736a8
2024-02-12T05:33:47Z info: Connecting to builder
2024-02-12T05:33:48Z info: Builder connected
2024-02-12T05:33:48Z info: Installing packages
--> poetry env list --full-path

2024-02-12T05:34:04Z info: Skipping Build as no Build command set
2024-02-12T05:34:04Z info: Pushing pid1 binary layer...
2024-02-12T05:34:05Z info: Created pid1 binary layer
2024-02-12T05:34:08Z info: Skipping Python layer creation
2024-02-12T05:34:08Z info: Skipping Node layer creation
2024-02-12T05:34:08Z info: Pushing hosting layer...
2024-02-12T05:34:08Z info: Pushing Repl layer...
2024-02-12T05:34:08Z info: Nix layers for this Repl are uncached.
2024-02-12T05:34:08Z info: Pushing nix-0 layer...
2024-02-12T05:34:09Z info: Created hosting layer
2024-02-12T05:34:54Z info: Created Repl layer
2024-02-12T05:35:44Z info: Created nix-0 layer
2024-02-12T05:35:44Z info: uploading image for cached layer
2024-02-12T05:35:44Z info: pushed cache image manifest
2024-02-12T05:35:45Z info: pushed cache soci index manifest
2024-02-12T05:35:45Z info: uploading cached layer
2024-02-12T05:35:45Z info: succesfully uploaded cached layer
2024-02-12T05:35:45Z info: Pushed image manifest
2024-02-12T05:35:45Z info: Pushed soci index manifest
2024-02-12T05:35:54Z info: Creating virtual machine
2024-02-12T05:36:04Z info: Virtual machine created
2024-02-12T05:36:04Z info: Waiting for deployment to be ready
Traceback (most recent call last):
exec [python3 main.py] error=exit status 1
ModuleNotFoundError: No module named 'flask'
starting up user application
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
exec [python3 main.py] error=exec: already started
    from flask import Flask, request, jsonify
exec [python3 main.py] error=exit status 1
starting up user application
Traceback (most recent call last):
ModuleNotFoundError: No module named 'flask'
    from flask import Flask, request, jsonify
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
exec [python3 main.py] error=exec: already started
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
Traceback (most recent call last):
starting up user application
    from flask import Flask, request, jsonify
ModuleNotFoundError: No module named 'flask'
exec [python3 main.py] error=exec: already started
exec [python3 main.py] error=exit status 1
exec [python3 main.py] error=exit status 1
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
Traceback (most recent call last):
    from flask import Flask, request, jsonify
exec [python3 main.py] error=exec: already started
starting up user application
ModuleNotFoundError: No module named 'flask'
    from flask import Flask, request, jsonify
exec [python3 main.py] error=exit status 1
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
ModuleNotFoundError: No module named 'flask'
Traceback (most recent call last):
starting up user application
exec [python3 main.py] error=exec: already started
starting up user application
    from flask import Flask, request, jsonify
Traceback (most recent call last):
ModuleNotFoundError: No module named 'flask'
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
exec [python3 main.py] error=exit status 1
exec [python3 main.py] error=exec: already started
    from flask import Flask, request, jsonify
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
exec [python3 main.py] error=exit status 1
starting up user application
Traceback (most recent call last):
exec [python3 main.py] error=exec: already started
ModuleNotFoundError: No module named 'flask'
    from flask import Flask, request, jsonify
Traceback (most recent call last):
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
exec [python3 main.py] error=exec: already started
exec [python3 main.py] error=exit status 1
starting up user application
ModuleNotFoundError: No module named 'flask'
Traceback (most recent call last):
ModuleNotFoundError: No module named 'flask'
exec [python3 main.py] error=exec: already started
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
exec [python3 main.py] error=exit status 1
starting up user application
    from flask import Flask, request, jsonify
starting up user application
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
exec [python3 main.py] error=exit status 1
ModuleNotFoundError: No module named 'flask'
Traceback (most recent call last):
    from flask import Flask, request, jsonify
exec [python3 main.py] error=exec: already started
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
    from flask import Flask, request, jsonify
Traceback (most recent call last):
starting up user application
exec [python3 main.py] error=exit status 1
ModuleNotFoundError: No module named 'flask'
exec [python3 main.py] error=exec: already started
starting up user application
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
exec [python3 main.py] error=exec: already started
Traceback (most recent call last):
    from flask import Flask, request, jsonify
ModuleNotFoundError: No module named 'flask'
exec [python3 main.py] error=exit status 1
    from flask import Flask, request, jsonify
exec [python3 main.py] error=exec: already started
ModuleNotFoundError: No module named 'flask'
starting up user application
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
Traceback (most recent call last):
exec [python3 main.py] error=exit status 1
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
starting up user application
    from flask import Flask, request, jsonify
Traceback (most recent call last):
exec [python3 main.py] error=exec: already started
ModuleNotFoundError: No module named 'flask'
exec [python3 main.py] error=exit status 1
exec [python3 main.py] error=exit status 1
  File "/home/runner/1a4d6456-dc20-4caa-8800-dea42977b323/main.py", line 1, in <module>
Traceback (most recent call last):
ModuleNotFoundError: No module named 'flask'
exec [python3 main.py] error=exec: already started
    from flask import Flask, request, jsonify
starting up user application

Hi @flixr !
Try forking the repl and see if the forked version works.
Hope this helps!

Hello @flixr!
Did you set a build command for your deployment?

Skipping Build as no Build command set

yeah I tried that twice already and it hasn’t fixed it unfortunately!

I haven’t but typically I’ve not seen this be an issue with any other deployments I’ve run

That shouldn’t change anything, as that’d be if you needed to, say, compile stuff before running it, which you don’t need to for a standard flask server.

Most likely, the path for .pythonlibs is missing from the PYTHONPATH env variable.

Click three dots and Show hidden files.
Provide the contents of both .replit and replit.nix files.

If this is indeed the problem, a workaround is to insert this at the bottom of .replit file, and refresh:

[env]
PYTHONPATH = "$REPL_HOME/.pythonlibs/lib/python3.10/site-packages:$PYTHONPATH"
1 Like

Here’s the .replit file:

entrypoint = "main.py"
modules = ["python-3.10:v18-20230807-322e88b"]

hidden = [".pythonlibs"]

[nix]
channel = "stable-23_05"

[unitTest]
language = "python3"

[deployment]
run = ["python3", "main.py"]
deploymentTarget = "gce"

and the replit.nix:

{ pkgs }: {
  deps = [
    pkgs.imagemagickBig
    pkgs.ffmpeg-full
    pkgs.python310Packages.opencv4
    pkgs.imagemagick
    pkgs.ffmpeg_6-full
  ];
  env = {
    IMAGEIO_FFMPEG_EXE = "${pkgs.ffmpeg_6-full}/bin/ffmpeg";
  };
}

I tried adding your suggestion to the .replit file but it caused errors when running in browser:

    bootstrap()
  File "/home/runner/Flixr-Subtitles/.pythonlibs/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

Okay.
Edit the previous code to this:

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

Refresh, and it should probably work.

A kill 1 should have the same effect.

Yes, any Shell command or even running the repl will also work.

Oh true, since it’s just an env edit.

this worked, thank you so much!

1 Like

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