fastai / nbdev

Create delightful software with Jupyter Notebooks
https://nbdev.fast.ai/
Apache License 2.0
4.8k stars 484 forks source link

nbdev does not export imports to modules. #1324

Closed LinuxIsCool closed 1 year ago

LinuxIsCool commented 1 year ago

If this is my jupyter:

#| export
import pandas as pd
#| export
def df():
    return pd.DataFrame()

Then after running nbdev_export, my module looks like:

def df():
    return pd.DataFrame()

And when I try to import and use the function somewhere else:

from package.module import df
a = df()

Then I get the error NameError: name 'pd' is not defined

deven367 commented 1 year ago

You don't see

import pandas as pd

in the module file?

LinuxIsCool commented 1 year ago

No it's not there.

deven367 commented 1 year ago

Can you make sure your nb looks like this? Also, if possible, can you share a small reproducible example?

#| default_exp module
#| export
import pandas as pd
#|export
def df():
    return pd.DataFrame()
LinuxIsCool commented 1 year ago

My bad. I had #| hide instead of #| export.