mljar / mercury

Convert Jupyter Notebooks to Web Apps
https://RunMercury.com
GNU Affero General Public License v3.0
4.04k stars 256 forks source link

import a python file from same folde as notebook #354

Closed wentzlau closed 1 year ago

wentzlau commented 1 year ago

I have a python file with common code that is used in multiple notebooks in the same folder as the python file. When running the notebook in vscode it works fine but when I use Mercury I get an error that the module is not found. Is there a way to share code between notebooks in Mercury?

wentzlau commented 1 year ago

Found a solution:

import sys
from pathlib import Path

# in jupyter (lab / notebook), based on notebook path
module_path = str(Path.cwd() )

if module_path not in sys.path:
    sys.path.append(module_path)

import mylib as ml
pplonski commented 1 year ago

Hi @wentzlau!

Great that you manage to solve the issue. May I ask, what is your use case for using Mercury?

wentzlau commented 1 year ago

I am working on a set of notebooks that displays various graphs/plots about local municipalities from the faroese statbank hagstova.fo. The statbank it self offers an online tool to get information, but it is difficult to use for people that are not used to work with data and computers. There fore i have started a little project where i use jupyter notebooks to fetch actual data from the statbank's public api and display graphs and plots. Each notebook contains a specific topic like demography, salary and working condition and so on.

The next step is to appify the notebooks and Mercury is just perfect for that.