mljar / mercury

Convert Jupyter Notebooks to Web Apps

Home Page:https://RunMercury.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

import a python file from same folde as notebook

wentzlau opened this issue · comments

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?

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
commented

Hi @wentzlau!

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

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.