Forum Discussion
Unexpected error in fabric pyspark notebook
Hi Everyone,
I am using Fabric pyspark notebook .It was as working fine until last month but when i am trying to run it now but showing error like F is not defined but I have already imported functions as F one time it runs successfully next time it gives error even if function or variable is already defined .Can anyone help me.
6 Replies
- tayloramy
Super User
Hi KJ14,
Can you post the full error message, and the structure of the notebook?
Are you using multiple cells? Are the imports in one cell but not another?
Are you running cells individually or all at once? Are you stopping and starting sessions mid way through running cells?
When a session stops, all context is lost, so previously run cells no longer have their outputs, or their imported functions.
- Kagiyama_yutaka
Skilled Sharer
If you don’t mind, can you share your cell layout and the full error text? Even a short snippet is fine. Without that, it’s basically guesswork and I can’t say why F is suddenly undefined.
Fabric notebooks sometimes drop state between runs, so imports or variables just disappear. I need to see the cell order + exact error to confirm if that’s the case.
- EduardoCastro
Helper I
Can you post part of the cell raising the error? I've been experiencing the exact same issue in my Fabric PySpark notebooks, and I think I've figured out what's causing it, if I do
from pyspark.sql import functions as F
and then I do some %pip install random-package I started getting the exact error, the reason is because %pip install restarts the kernel and you imported functions are gone.
That was my case, maybe can help you.
- rizalard0684
Resolver IV
hey KJ14 please share the error message and let's see if we can help you.
My guess (exploring using Copilot), the error "F is not defined" may indicate that the Spark session was restarted and the notebook lost variables/imports that were previously loaded. Making sure the import cell is executed before any cell that uses that "F" could help.
- v-achippa
Community Support
Hi KJ14,
Thank you for reaching out to Microsoft Fabric Community.
Thank you tayloramy, Kagiyama_yutaka and rizalard0684 for the prompt response.
As we haven’t heard back from you, we wanted to kindly follow up to check if your issue is resolved?
If not provide the details mentioned by the user's and provide the full error message that covers your issue or question completely, in a usable format (not as a screenshot). Do not include sensitive information or anything unrelated to the issue or question.Thanks and regards,
Anjan Kumar Chippa - v-achippa
Community Support
Hi KJ14,
We wanted to kindly follow up to check if your issue is resolved? If not provide the details mentioned by the user's and provide the full error message that covers your issue or question completely, in a usable format. Do not include sensitive information or anything unrelated to the issue or question.
Thanks and regards,
Anjan Kumar Chippa