Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
15.45k stars 1.86k forks source link

[🐛 BUG] Getting OS Error while using the GUI module. #1779

Open RandomArnab opened 2 months ago

RandomArnab commented 2 months ago

What went wrong? 🤔

Can't use the GUI module properly from an interactive Python prompt. image

=>

 File "C:\Users\arnaa\AppData\Local\Programs\Python\Python312\Lib\inspect.py", line 1096, in findsource
    raise OSError('could not get source code')
OSError: could not get source code

Proposed 'solution' (well it's not, really)

Taipy GUI cannot function properly in these conditions because it relies heavily on an actual Python source file, such as one available when running a script or from a Notebook session. Currently, there is no feasible workaround for this limitation.

To address this, we should document the limitation clearly and implement an error message that accurately explains the issue, replacing the existing cryptic exception message.

Acceptance Criteria

Code of Conduct

FlorianJacta commented 2 months ago

What Taipy version are you using? Do you use any tools that can conflict with Taipy?

RandomArnab commented 2 months ago

Taipy version is 3.1.1. I've tried it on multiple environments with python versions of 3.11 and 3.12 but got the same os error while calling the GUI module.

FlorianJacta commented 2 months ago

Thank you for the quick answer! Are you coding in a cloud environment?

Can you test:

from taipy.gui import Gui 

Gui(page="# Hello world").run()
RandomArnab commented 2 months ago

No, I'm running locally. Still the same error however. image

FlorianJacta commented 2 months ago

Did you create a brand new environment for your Taipy installation? Maybe, that could fix this issue.

@FabienLelaquais @FredLL-Avaiga Do you have any idea?

RandomArnab commented 2 months ago

I tried both ways, on my pre-existing environment with 3.11 python version and on a new environment with 3.12.

FredLL-Avaiga commented 2 months ago

if think the problem is that you're trying in the console and we need a file...

FredLL-Avaiga commented 2 months ago

I guess we should give a proper error message

FlorianJacta commented 2 months ago

True, I can replicate the issue:

>>> from taipy.gui import Gui
>>> Gui("Hello").run()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jacta\.conda\envs\4.0\Lib\site-packages\taipy\gui\gui.py", line 2705, in run
    self.__var_dir.set_default(self.__frame)
  File "C:\Users\jacta\.conda\envs\4.0\Lib\site-packages\taipy\gui\utils\_variable_directory.py", line 31, in set_default
    self.add_frame(frame)
  File "C:\Users\jacta\.conda\envs\4.0\Lib\site-packages\taipy\gui\utils\_variable_directory.py", line 38, in add_frame
    imported_var_list = _get_imported_var(frame)
                        ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jacta\.conda\envs\4.0\Lib\site-packages\taipy\gui\utils\get_imported_var.py", line 21, in _get_imported_var
    st = ast.parse(inspect.getsource(frame))
                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jacta\.conda\envs\4.0\Lib\inspect.py", line 1279, in getsource
    lines, lnum = getsourcelines(object)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jacta\.conda\envs\4.0\Lib\inspect.py", line 1261, in getsourcelines
    lines, lnum = findsource(object)
                  ^^^^^^^^^^^^^^^^^^
  File "C:\Users\jacta\.conda\envs\4.0\Lib\inspect.py", line 1090, in findsource
    raise OSError('could not get source code')
OSError: could not get source code

You should use Python files to run a Taipy application.

Paulie-Aditya commented 1 month ago

using python files should solve the issue. As far as I understood the issue is occurring due to the code being run on a python console

SGCODEX commented 1 month ago

@jrobinAV @Dr-Irv Hi, please assign me this issue under Devfest ai and Hacktoberfest

FlorianJacta commented 1 month ago

It seems that you are already assigned to another issue @SGCODEX

aniketh-varma commented 1 month ago

Hi @FlorianJacta, I can work on this issue. It would be great if you could explain the steps required to solve the issue/preferred solution since this will be my first PR for this repo.

jrobinAV commented 1 month ago

@aniketh-varma Let me assign the issue to you. Thanks for your help.

For your questions, I let @FabienLelaquais @FredLL-Avaiga @dinhlongviolin1 @namnguyen20999 answer. They are the right persons.

aniketh-varma commented 1 month ago

Hey @FabienLelaquais @FredLL-Avaiga @dinhlongviolin1 @namnguyen20999 , can you please help me with a preferred solution for the issue.

FabienLelaquais commented 1 month ago

Hi @RandomArnab, @aniketh-varma, and @SGCODEX. Thank you for your interest in the topic.

Unfortunately (or fortunately), @Paulie-Aditya is right (and @FlorianJacta confirms it): Taipy GUI cannot run straight from the console because it needs runtime information (like locating callback functions or tricky bindings) that are available only when the script is an actual file. Interactive Python interpreters do not provide such a facility, and we fail to do anything.

As @FredLL-Avaiga points out, the least Taipy could do is document this limitation and issue a more informative error message. We will, in the short term.

I recommend we keep this issue open, and I add a note on this discovery in the description.

Thanks again,

quest-bot[bot] commented 1 month ago

New Quest! image New Quest!

A new Quest has been launched in @Avaiga’s repo. Merge a PR that solves this issue to loot the Quest and earn your reward.


Some loot has been stashed in this issue to reward the solver!

🗡 Comment @quest-bot embark to check-in for this Quest and start solving the issue. Other solvers will be notified!

⚔️ When you submit a PR, comment @quest-bot loot #1779 to link your PR to this Quest.

Questions? Check out the docs.

github-actions[bot] commented 4 weeks ago

This issue has been labelled as "🥶Waiting for contributor" because it has been inactive for more than 14 days. If you would like to continue working on this issue, please add another comment or create a PR that links to this issue. If a PR has already been created which refers to this issue, then you should explicitly mention this issue in the relevant PR. Otherwise, you will be unassigned in 14 days. For more information please refer to the contributing guidelines.

github-actions[bot] commented 1 week ago

This issue has been unassigned automatically because it has been marked as "🥶Waiting for contributor" for more than 14 days with no activity.