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

Issues installing and running lightning in Pipenv #14789

Closed
awaelchli opened this issue Sep 19, 2022 · 5 comments
Closed

Issues installing and running lightning in Pipenv #14789

awaelchli opened this issue Sep 19, 2022 · 5 comments
Assignees
Labels
app (removed) Generic label for Lightning App package bug Something isn't working priority: 0 High priority task
Milestone

Comments

@awaelchli
Copy link
Contributor

awaelchli commented Sep 19, 2022

Bug description

The original report is here (internal access only): https://linear.app/lightning-ai/issue/LAI2-8803/use-python-m-pip-in-all-examples

It seems that users who create an environment with Pipenv can't install Lightning or run apps without prefixing python -m. The python -m cancer is spreading to examples and documentation, but is clearly diminishing the UX for users. A real CLI shouldn't require this awkward prefix.

How to reproduce the bug

Pending, I need to verify this. 


1. create Pipenv environment
2. pip install lightning  # fails
3. python -m pip install lightning  # works
4. lightning run app app.py  # fails
5. python -m lightning run app app.py  # works

Error messages and logs

TODO

Important info


#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0):
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 1.10):
#- Python version (e.g., 3.9):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):
#- Running environment of LightningApp (e.g. local, cloud):

More info

A PR attempting to fix this (or something related) was made at launch on the old repo: https://github.com/Lightning-AI/lightning-app/pull/855

We have guides for virtualenv and conda on our beginner guide for installation. Until this issue is resolved, we should communicate that Pipenv is not supported and that support is coming soon.

@awaelchli awaelchli added bug Something isn't working needs triage Waiting to be triaged by maintainers priority: 0 High priority task app (removed) Generic label for Lightning App package and removed needs triage Waiting to be triaged by maintainers labels Sep 19, 2022
@awaelchli awaelchli added this to the app:0.6.x milestone Sep 19, 2022
@awaelchli
Copy link
Contributor Author

awaelchli commented Sep 28, 2022

Received new repro instructions from @krishnakalyan3:

conda create -n break python=3.8
conda activate break

requirements.txt file:

youtube-dl
git+https://github.com/openai/whisper
lightning
gradio

app.py file:

import lightning as L
from lightning_app.components.serve import ServeGradio
import gradio as gr
import whisper


class LitGradio(ServeGradio):

    inputs = gr.inputs.Textbox(default='lightning', label='name input')
    outputs = gr.outputs.Textbox(label='output')
    examples = [["hello lightning"]]

    def predict(self, input_text):
        return self.model(input_text)

    def build_model(self):
        fake_model = lambda x: f"hello {x}"
        return fake_model

class RootFlow(L.LightningFlow):
    def __init__(self):
        super().__init__()
        self.lit_gradio = LitGradio()

    def run(self):
        self.lit_gradio.run()

    def configure_layout(self):
        return [{"name": "home", "content": self.lit_gradio}]

app = L.LightningApp(RootFlow())

Error:

lightning run app app.py --cloud

Your Lightning App is starting. This won't take long.
ERROR: Found an exception when loading your application from app_break.py. Please, resolve it to run your app.

Traceback (most recent call last):
  File "app_break.py", line 4, in <module>
    import whisper
ModuleNotFoundError: No module named 'whisper'

He reports that running with python -m works fine:


python -m lightning run app app.py --cloud
The name of the app is: vengeful-zhukovsky-8511
upload ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0%
Application is ready in the cloud

Despite these precise instructions, I could not reproduce on my machine (M1 Mac, Miniconda) :(

@krishnakalyan3
Copy link
Contributor

krishnakalyan3 commented Sep 28, 2022

I tested this on my personal ubuntu laptop. Perhaps this issue is because of me using anaconda incorrectly.

@awaelchli awaelchli mentioned this issue Sep 29, 2022
12 tasks
@krishnakalyan3
Copy link
Contributor

This is what I found in my investigation. I am using M1 mac

Step 1: which lightning
> /opt/homebrew/bin/lightning
Looks like homebrew cli overrides anaconda CLI
Step 2: Remove Homebrew Reference
cd /opt/homebrew/bin/
ls | grep lightning
rm lightning
rm lightning_cloud
Step 3: Things should work normally, without python -m

@otaj
Copy link
Contributor

otaj commented Nov 7, 2022

So, I think I figured out the problem. When you install a package, all of its entrypoints are prepended with a shebang containing absolute path to current python version used when installing such package.

This for example means that in my environment, lightning script, that gets installed is prepended with this line:
#!/home/otaj/.pyenv/versions/3.10.6/envs/lightning-dev/bin/python3.10

One solution would be to not register lightning as console_script, but as a script in entry_points, but that comes with quite a bit of its own problems (the script that gets installed then just gets literally only copied, so it would need to be called lightning and made executable and have a "better" shebang (#!/usr/bin/env python), but this shebang is then not multi-platform)

In general, it seems that the issue is caused by not running lightning in the exactly same environment where it was installed. I know @ethanwharris has been working on a workaround that would detect you are running with a different python than expected and correct it (#15434), which should be included in a fairly recent release, so we'll see, if tha tactually solves it for everyone

@carmocca carmocca assigned ethanwharris and unassigned otaj Nov 7, 2022
@awaelchli
Copy link
Contributor Author

This issue did not occur anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app (removed) Generic label for Lightning App package bug Something isn't working priority: 0 High priority task
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants