Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Docker Compose #3546

Closed
alvarolucasno opened this issue Aug 26, 2024 · 3 comments
Closed

Error Docker Compose #3546

alvarolucasno opened this issue Aug 26, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@alvarolucasno
Copy link

Bug Description

When deploying the stack in Portainer, I received the following error.

Reproduction

Stack:

version: "3.8"

services:
langflow:
image: langflowai/langflow:latest
ports:
- "7860:7860"
depends_on:
- postgres
environment:
- LANGFLOW_DATABASE_URL=postgresql://langflow:langflow@postgres:5432/langflow
volumes:
- langflow-data:/app/langflow

postgres:
image: postgres:16
environment:
POSTGRES_USER: langflow
POSTGRES_PASSWORD: langflow
POSTGRES_DB: langflow
ports:
- "5432:5432"
volumes:
- langflow-postgres:/var/lib/postgresql/data

volumes:
langflow-postgres:
langflow-data:

Erro:

                         "DatabaseService" =                                
                         get_db_service()                                   
                                                                            
                                 ^^^^^^^^^^^^^^^^                           
                           File                                             
                         "/app/.venv/lib/python3.12/site-pa                 
                         ckages/langflow/services/deps.py",                 
                          line 154, in get_db_service                       
                             return                                         
                         get_service(ServiceType.DATABASE_S                 
                         ERVICE, DatabaseServiceFactory())                  
                         # type: ignore                                     
                                    ^^^^^^^^^^^^^^^^^^^^^^^                 
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                 
                         ^^^^^^^^^^                                         
                           File                                             
                         "/app/.venv/lib/python3.12/site-pa                 
                         ckages/langflow/services/deps.py",                 
                          line 43, in get_service                           
                             return                                         
                         service_manager.get(service_type,                  
                         default)  # type: ignore                           
                                    ^^^^^^^^^^^^^^^^^^^^^^^                 
                         ^^^^^^^^^^^^^^^^^^^                                
                           File                                             
                         "/app/.venv/lib/python3.12/site-pa                 
                         ckages/langflow/services/manager.p                 
                         y", line 57, in get                                
                             self._create_service(service_n                 
                         ame, default)                                      
                           File                                             
                         "/app/.venv/lib/python3.12/site-pa                 
                         ckages/langflow/services/manager.p                 
                         y", line 81, in _create_service                    
                             self.services =                                
                         self.factories.create(**dependent_                 
                         services)                                          
                                                                            
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                 
                         ^^^^^^^^^^^^^^^^^^^^^^^                            
                           File                                             
                         "/app/.venv/lib/python3.12/site-pa                 
                         ckages/langflow/services/database/                 
                         factory.py", line 18, in create                    
                             return                                         
                         DatabaseService(settings_service)                  
                                    ^^^^^^^^^^^^^^^^^^^^^^^                 
                         ^^^^^^^^^^                                         
                           File                                             
                         "/app/.venv/lib/python3.12/site-pa                 
                         ckages/langflow/services/database/                 
                         service.py", line 46, in __init__                  
                             self.engine =                                  
                         self._create_engine()                              
                                           ^^^^^^^^^^^^^^^^                 
                         ^^^^^                                              
                           File                                             
                         "/app/.venv/lib/python3.12/site-pa                 
                         ckages/langflow/services/database/                 
                         service.py", line 64, in                           
                         _create_engine                                     
                             return create_engine(                          
                                    ^^^^^^^^^^^^^^                          
                           File "<string>", line 2, in                      
                         create_engine                                      
                           File                                             
                         "/app/.venv/lib/python3.12/site-pa                 
                         ckages/sqlalchemy/util/deprecation                 
                         s.py", line 281, in warned                         
                             return fn(*args, **kwargs)  #                  
                         type: ignore                                       
                                    ^^^^^^^^^^^^^^^^^^^                     
                           File                                             
                         "/app/.venv/lib/python3.12/site-pa                 
                         ckages/sqlalchemy/engine/create.py                 
                         ", line 599, in create_engine                      
                             dbapi =                                        
                         dbapi_meth(**dbapi_args)                           
                                     ^^^^^^^^^^^^^^^^^^^^^^                 
                         ^^                                                 
                           File                                             
                         "/app/.venv/lib/python3.12/site-pa                 
                         ckages/sqlalchemy/dialects/postgre                 
                         sql/psycopg2.py", line 690, in                     
                         import_dbapi                                       
                             import psycopg2                                
                         ModuleNotFoundError: No module                     
                         named 'psycopg2'                                   
                                                                            
                ERROR    2024-08-26 10:57:08 - ERROR    -   __init__.py:1762
                         __init__ - Application startup                     
                         failed. Exiting.                                   

[08/26/24 10:57:08] ERROR 2024-08-26 10:57:08 - ERROR - init.py:1762
init - Worker (pid:19) exited
with code 3
ERROR 2024-08-26 10:57:08 - ERROR - init.py:1762
init - Shutting down: Master
ERROR 2024-08-26 10:57:08 - ERROR - init.py:1762
init - Reason: Worker failed
to boot.

Expected behavior

Service execution and application start.

Who can help?

@italojohnny

Operating System

Docker Swarm

Langflow Version

latest

Python Version

None

Screenshot

No response

Flow File

No response

@alvarolucasno alvarolucasno added the bug Something isn't working label Aug 26, 2024
Copy link

dosubot bot commented Aug 26, 2024

Hello, @alvarolucasno! I'm here to assist you with bugs, questions, and becoming a contributor. Let's squash those bugs together! 🤖

To resolve the "ModuleNotFoundError: No module named 'psycopg2'" error when deploying the stack in Docker Compose, you need to ensure that the psycopg2 module is installed in the Docker image used for the langflow service.

You can do this by modifying the Dockerfile for the langflow service to include the installation of psycopg2. Here is an example of how you can modify the Dockerfile:

# Use the official Python image from the Docker Hub
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt .

# Install the dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Install psycopg2
RUN pip install psycopg2-binary

# Copy the rest of the application code into the container
COPY . .

# Command to run the application
CMD ["python", "app.py"]

Make sure your requirements.txt file includes all the necessary dependencies for your application, but you can also directly install psycopg2 as shown above.

After modifying the Dockerfile, you need to rebuild the Docker image and redeploy the stack:

docker-compose build langflow
docker-compose up -d

This will ensure that the psycopg2 module is available in the langflow service, resolving the "ModuleNotFoundError: No module named 'psycopg2'" error [1].

To continue talking to Dosu, mention @dosu.

@alvarolucasno
Copy link
Author

In this case, I have to rebuild the image. If it's possible to add this step to the image available on DOCKER HUB, it would make things simpler. Anyway, thank you!

@italojohnny
Copy link
Member

Hi, @alvarolucasno . I hope you're doing well.
The issue you're facing has been resolved in PR #3526. In the next release, you won't have to deal with this problem anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants