mljar / mercury

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

Import module error #370

Closed jl-calda closed 11 months ago

jl-calda commented 1 year ago

Would like some clarity about the following.

Below is my file structure Screenshot 2023-10-07 at 12 31 04 PM

It is working Screenshot 2023-10-07 at 12 31 55 PM on VSCode

But when running mercury it can't find my constants import

Screenshot 2023-10-07 at 12 30 28 PM

Thanks

pplonski commented 1 year ago

Hi @jl-calda,

Please try to add to notebook

import sys
print(sys.path)

Do you have the same output in vs code and mercury?

jl-calda commented 1 year ago

Hi @pplonski

They are not same as shown below.

From Mercury

['/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages/mercury', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages/mercury/apps/..', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages/mercury/apps/..', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages/mercury/apps/nbworker', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python310.zip', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/lib-dynload', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages']

From VS Code ['/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages/mercury', '/Users/jlcalda/Documents/jupyter notebooks/mercury', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python310.zip', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/lib-dynload', '', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages']

pplonski commented 1 year ago

Please add missing path to sys.path before importing module. Example:

import sys
sys.path.append("path_to_my_module")

import my_module
jl-calda commented 11 months ago

Thanks. Read how python does import. Figured it out now.

Yugal0 commented 8 months ago

Hi @jl-calda,

Please try to add to notebook

import sys
print(sys.path)

Do you have the same output in vs code and mercury?

What does it mean to run this in mercury?

pplonski commented 8 months ago

It is just to check your paths in the notebook in Mercury.

Yugal0 commented 8 months ago

It is just to check your paths in the notebook in Mercury.

Can you please explain in more detail? step-by-step please. I couldn't see a terminal in mercury.

pplonski commented 8 months ago

Sure, user has problem with module import, and I suggested to check imported packages by printing sys.path. Do you have problem with package import in Mercury notebook? What is your issue? Maybe it will be good idea to create new github issue?

Yugal0 commented 8 months ago

Sure, user has problem with module import, and I suggested to check imported packages by printing sys.path. Do you have problem with package import in Mercury notebook? What is your issue? Maybe it will be good idea to create new github issue?

I can't understand what mercury notebook means? and how do I write code there. As of now I only see a webapp open by mercury.

pplonski commented 8 months ago

The mercury notebook is a notebook opened by mercury. It is a web app. You need to develop notebook in Jupyter Lab. If you have Python notebook ready, then you can serve it as web app.

Yugal0 commented 8 months ago

Hi @pplonski

They are not same as shown below.

From Mercury

['/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages/mercury', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages/mercury/apps/..', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages/mercury/apps/..', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages/mercury/apps/nbworker', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python310.zip', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/lib-dynload', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages']

From VS Code ['/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages/mercury', '/Users/jlcalda/Documents/jupyter notebooks/mercury', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python310.zip', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/lib-dynload', '', '/Users/jlcalda/Documents/jupyter notebooks/.conda/lib/python3.10/site-packages']

Then how do I get this output from mercury, I can get this from VScode (jupyter in VScode) already

pplonski commented 8 months ago

Hi @Yugal0,

Probably you are using different kernel / environment in VS Code and in Mercury. Please double check if you are using the same environment.