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

Installing a pre-release and facing runtime error on macOS #2049

Closed
GimmeSomeJazz opened this issue Jun 3, 2024 · 11 comments
Closed

Installing a pre-release and facing runtime error on macOS #2049

GimmeSomeJazz opened this issue Jun 3, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@GimmeSomeJazz
Copy link

@ogabrielluiz thank you for all. I replicated @msmygit successful pattern described here, but I have the following same error with langchain_cohere module when running langflow (installation was successful). Thank you for your help!

Starting Langflow v1.0.0a43... 

[05/31/24 22:14:15] ERROR    2024-05-31 22:14:15 - ERROR    - code_parser - Module langchain_cohere not found. Please install it code_parser.py:300 and try againTraceback (most recent call last):                                                                       
                                                                                                                                                   
   File "/Users/u721624/.pyenv/versions/langflow/lib/python3.10/site-packages/fastavro/read.py",                       
 line 2, in <module>                                                                                                   
     from . import _read                                                                                               
   File "fastavro/_read.pyx", line 10, in init fastavro._read                                                          
   File "/Users/u721624/.pyenv/versions/3.10.14/lib/python3.10/lzma.py", line 27, in <module>                          
     from _lzma import *                                                                                               
                                                                                                                       
 ModuleNotFoundError: No module named '_lzma'                                                                          
                                                                                                                       
                                                                                                                       
 During handling of the above exception, another exception occurred:      
@dosubot dosubot bot added the bug Something isn't working label Jun 3, 2024
Copy link

dosubot bot commented Jun 3, 2024

Hey there, @GimmeSomeJazz! I'm here to help you out with any bugs, questions, or contributions you have in mind. Let's squash those bugs together while we wait for a human maintainer.

To resolve the issue with the langchain_cohere module and the _lzma module on macOS, follow these steps:

  1. Install the langchain_cohere module and its dependencies:

    pip install langchain-cohere==0.1.0rc1
    pip install cohere==5.5.3
  2. Fix the _lzma module issue:
    The _lzma module is part of the lzma library, which may not be installed by default on macOS. You can install it using Homebrew:

    brew install xz

    After installing xz, you may need to reinstall Python to ensure it includes support for lzma:

    pyenv install 3.10.14
    pyenv global 3.10.14
  3. Set environment variables for macOS:
    Ensure you set the necessary environment variables to avoid errors when running Langflow on macOS:

    export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
    export no_proxy=*
  4. Run Langflow:
    Start Langflow with the following command:

    python -m langflow run

These steps should help resolve the issues you're encountering with the langchain_cohere module and the _lzma module on macOS [1][2].

To continue talking to Dosu, mention @dosu.

@GimmeSomeJazz GimmeSomeJazz changed the title Installing a pre-release and facing runtime on macOS Installing a pre-release and facing runtime error on macOS Jun 3, 2024
@GimmeSomeJazz
Copy link
Author

GimmeSomeJazz commented Jun 3, 2024

hey @dosu. That resolved my first issue. Now I am facing a httpx.ConnectError due to a Request('GET', 'https://pypi.org/pypi/langflow/json') somewhere at the runtime. Certainly due to proxy issues. Any idea to resolve it / to set my proxy? Thank you! (so strange to say thank you to a bot haha)

Copy link

dosubot bot commented Jun 3, 2024

To resolve the httpx.ConnectError due to a Request('GET', 'https://pypi.org/pypi/langflow/json') at runtime, likely caused by proxy issues, you need to correctly set your proxy on macOS. You can configure the proxy settings in your httpx client as follows:

import httpx

proxies = {
    "http://": "http://your_proxy_address:your_proxy_port",
    "https://": "http://your_proxy_address:your_proxy_port",
}

async def make_request_with_proxy():
    async with httpx.AsyncClient(proxies=proxies) as client:
        try:
            response = await client.get('https://pypi.org/pypi/langflow/json')
            response.raise_for_status()
            return response.json()
        except httpx.ConnectError as e:
            print(f"Connection error: {e}")
        except httpx.HTTPStatusError as e:
            print(f"HTTP error: {e}")

# Run the request
import asyncio
asyncio.run(make_request_with_proxy())

Replace your_proxy_address and your_proxy_port with your actual proxy address and port. This should help you bypass the proxy issues and successfully make the request [1].

To continue talking to Dosu, mention @dosu.

@GimmeSomeJazz
Copy link
Author

GimmeSomeJazz commented Jun 3, 2024

does not working for me @dosu. I have this error when I run the command python -m langflow run and I cannot modify the langflow code at runtime!
The error comes from here :


langflow/__main__.py:303 in 
│ fetch_latest_version                                                                             
│                                                                                                  
│   300                                                                                            
│   301                                                                                            
│   302 def fetch_latest_version(package_name: str, include_prerelease: bool) -> Optional[str]:    
│ ❱ 303 │   response = httpx.get(f"https://pypi.org/pypi/{package_name}/json")                     
│   304 │   versions = response.json()["releases"].keys()                                          
│   305 │   valid_versions = [v for v in versions if include_prerelease or not is_prerelease(v)]   
│   306 │   if not valid_versions:                                                                 
│                                                                                                  
│ ╭──────────── locals ─────────────╮                                                              
│ │ include_prerelease = True       │                                                              
│ │       package_name = 'langflow' │                                                             
│ ╰─────────────────────────────────╯                                                              

Copy link

dosubot bot commented Jun 3, 2024

To resolve the proxy issue causing an httpx.ConnectError when running python -m langflow run on macOS, you need to set the no_proxy environment variable to *. This is already handled in the set_var_for_macos_issue function in the provided code.

Ensure that this function is called before running the server, which is already done in the run function:

def set_var_for_macos_issue():
    if platform.system() in ["Darwin"]:
        import os
        os.environ["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
        os.environ["no_proxy"] = "*"
        logger.debug("Set OBJC_DISABLE_INITIALIZE_FORK_SAFETY to YES to avoid error")

def run(
    host: str = typer.Option("127.0.0.1", help="Host to bind the server to.", envvar="LANGFLOW_HOST"),
    workers: int = typer.Option(1, help="Number of worker processes.", envvar="LANGFLOW_WORKERS"),
    timeout: int = typer.Option(300, help="Worker timeout in seconds.", envvar="LANGFLOW_WORKER_TIMEOUT"),
    port: int = typer.Option(7860, help="Port to listen on.", envvar="LANGFLOW_PORT"),
    components_path: Optional[Path] = typer.Option(
        Path(__file__).parent / "components",
        help="Path to the directory containing custom components.",
        envvar="LANGFLOW_COMPONENTS_PATH",
    ),
    env_file: Path = typer.Option(None, help="Path to the .env file containing environment variables."),
    log_level: str = typer.Option("critical", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"),
    log_file: Path = typer.Option("logs/langflow.log", help="Path to the log file.", envvar="LANGFLOW_LOG_FILE"),
    cache: Optional[str] = typer.Option(
        envvar="LANGFLOW_LANGCHAIN_CACHE",
        help="Type of cache to use. (InMemoryCache, SQLiteCache)",
        default=None,
    ),
    dev: bool = typer.Option(False, help="Run in development mode (may contain bugs)"),
    path: str = typer.Option(
        None,
        help="Path to the frontend directory containing build files. This is for development purposes only.",
        envvar="LANGFLOW_FRONTEND_PATH",
    ),
    open_browser: bool = typer.Option(
        True,
        help="Open the browser after starting the server.",
        envvar="LANGFLOW_OPEN_BROWSER",
    ),
    remove_api_keys: bool = typer.Option(
        False,
        help="Remove API keys from the projects saved in the database.",
        envvar="LANGFLOW_REMOVE_API_KEYS",
    ),
    backend_only: bool = typer.Option(
        False,
        help="Run only the backend server without the frontend.",
        envvar="LANGFLOW_BACKEND_ONLY",
    ),
    store: bool = typer.Option(
        True,
        help="Enables the store features.",
        envvar="LANGFLOW_STORE",
    ),
):
    configure(log_level=log_level, log_file=log_file)
    set_var_for_macos_issue()
    if env_file:
        load_dotenv(env_file, override=True)
    update_settings(
        dev=dev,
        remove_api_keys=remove_api_keys,
        cache=cache,
        components_path=components_path,
        store=store,
    )
    static_files_dir: Optional[Path] = Path(path) if path else None
    app = setup_app(static_files_dir=static_files_dir, backend_only=backend_only)
    if is_port_in_use(port, host):
        port = get_free_port(port)
    settings_service = get_settings_service()
    settings_service.set("worker_timeout", timeout)
    options = {
        "bind": f"{host}:{port}",
        "workers": get_number_of_workers(workers),
        "timeout": timeout,
    }
    if "pytest" in sys.modules:
        return
    try:
        if platform.system() in ["Windows"]:
            process = run_on_windows(host, port, log_level, options, app)
        else:
            process = run_on_mac_or_linux(host, port, log_level, options, app)
        if open_browser:
            click.launch(f"http://{host}:{port}")
        if process:
            process.join()
    except KeyboardInterrupt:
        pass

Make sure the set_var_for_macos_issue function is being executed by adding a debug statement or print statement to confirm its execution [1][2].

To continue talking to Dosu, mention @dosu.

@GimmeSomeJazz
Copy link
Author

GimmeSomeJazz commented Jun 3, 2024

does not working for me @dosu. I have this error when I run the command python -m langflow run and I cannot modify the langflow code at runtime! Is there any options in langflow to set proxy / ssl configuration?
The error comes from here :


langflow/__main__.py:303 in 
│ fetch_latest_version                                                                             
│                                                                                                  
│   300                                                                                            
│   301                                                                                            
│   302 def fetch_latest_version(package_name: str, include_prerelease: bool) -> Optional[str]:    
│ ❱ 303 │   response = httpx.get(f"https://pypi.org/pypi/{package_name}/json")                     
│   304 │   versions = response.json()["releases"].keys()                                          
│   305 │   valid_versions = [v for v in versions if include_prerelease or not is_prerelease(v)]   
│   306 │   if not valid_versions:                                                                 
│                                                                                                  
│ ╭──────────── locals ─────────────╮                                                              
│ │ include_prerelease = True       │                                                              
│ │       package_name = 'langflow' │                                                             
│ ╰─────────────────────────────────╯                                                              

Copy link

dosubot bot commented Jun 3, 2024

To resolve the httpx.ConnectError due to a proxy issue when running python -m langflow run on macOS without modifying the Langflow code at runtime, you can set the no_proxy environment variable to bypass the proxy for local addresses. This can be done by setting the environment variable before running the command.

Here is how you can do it in the terminal:

export no_proxy="*"
python -m langflow run

Additionally, Langflow has a built-in function set_var_for_macos_issue that sets the no_proxy environment variable to * to avoid errors with gunicorn on macOS. This function is called within the run command of Langflow, ensuring that the necessary environment variables are set automatically when running the application [1][2][3].

To continue talking to Dosu, mention @dosu.

@GimmeSomeJazz
Copy link
Author

@dosu, it does not work. I need to talk to one human please.

Copy link

dosubot bot commented Jun 3, 2024

@ogabrielluiz, this one's a bit out of my wheelhouse, could you step in and provide your guidance?

To continue talking to Dosu, mention @dosu.

@GimmeSomeJazz
Copy link
Author

@dosu @ogabrielluiz I had that error message, but the gui seems to load in fact (ConnectError: [Errno 8] nodename nor servname provided, or not known). So I will try, and if things go ok, I close the issue!

Copy link

dosubot bot commented Jun 3, 2024

It looks like the issue with the httpx.ConnectError due to proxy settings is a bit tricky. Here are a few steps you can try to resolve it:

  1. Set the no_proxy Environment Variable:
    Ensure that the no_proxy environment variable is set to * to bypass the proxy for local addresses. You can do this in your terminal before running Langflow:

    export no_proxy="*"
    python -m langflow run
  2. Check the set_var_for_macos_issue Function:
    Langflow has a built-in function set_var_for_macos_issue that sets the no_proxy environment variable to * to avoid errors with gunicorn on macOS. This function is called within the run command of Langflow, ensuring that the necessary environment variables are set automatically when running the application.

  3. Proxy Configuration in httpx:
    If you need to set a proxy for httpx, you can configure it in your code. However, since you mentioned you cannot modify the Langflow code at runtime, this might not be directly applicable. But for reference, here's how you can set up a proxy in httpx:

    import httpx
    
    proxies = {
        "http://": "http://your_proxy_address:your_proxy_port",
        "https://": "http://your_proxy_address:your_proxy_port",
    }
    
    async def make_request_with_proxy():
        async with httpx.AsyncClient(proxies=proxies) as client:
            try:
                response = await client.get('https://pypi.org/pypi/langflow/json')
                response.raise_for_status()
                return response.json()
            except httpx.ConnectError as e:
                print(f"Connection error: {e}")
            except httpx.HTTPStatusError as e:
                print(f"HTTP error: {e}")
    
    # Run the request
    import asyncio
    asyncio.run(make_request_with_proxy())
  4. Running Langflow:
    After setting the no_proxy environment variable, try running Langflow again:

    python -m langflow run

If the GUI loads and works fine despite the ConnectError, you might be able to proceed without further issues. If you continue to face problems, it might be best to get in touch with a human maintainer for more specific guidance.

@ogabrielluiz, could you please provide further assistance if needed?

Let us know how it goes!

To continue talking to Dosu, mention @dosu.

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

1 participant