evalf / nutils

The nutils project
http://www.nutils.org/
MIT License
88 stars 48 forks source link

Spyder Issue #778

Closed Shant1999 closed 1 year ago

Shant1999 commented 1 year ago

Hello, I have this issue with nutils where my spyder does not recognize it. When I run the example script for Cahn-Hillard equations, I get the following error:

ModuleNotFoundError: No module named 'nutils'

I have followed many instructions on how to solve this, reinstalled spyder (I have the latest version for everything), reinstalled nutils, restarted my computer (multiple times), but I can't seem to get it working. Are there any suggestions of what I can do to fix this issue?

( This video came close to the issue I was having: https://youtu.be/i7Njb3xO4Fw), but running into anaconda prompt gave me errors.

Thanks in advance,

Shant.

joostvanzwieten commented 1 year ago

It sounds like you have multiple versions of Python on your computer. Spyder uses one and you have installed Nutils in the other. Did you install Nutils in a terminal using pip install nutils? If so, can you verify that you can run the Cahn-Hilliard script in a terminal using python3 cahnhilliard.py or python cahnhilliard.py?

Shant1999 commented 1 year ago

Hey Joost,

Thank you for the reply. I have deleted all Anaconda from my PC and uninstalled Spyder (all of it) and redid everything. Even reinstalled nutils again. I did download nutils in a terminal using pip install (I followed all the steps). When I tried to verify the cahn-hillard script in the termal of anaconda prompt that didn't work (not sure if you meant anaconda only?). I also put it in the terminal for Spyder and it gave me this:

python Cahn-Hilliard.py File "C:\Users\Shant\AppData\Local\Temp\ipykernel_19008\1985523429.py", line 1 python Cahn-Hilliard.py ^ SyntaxError: invalid syntax

Unfortunately I still get the same error when I run the Cahn-Hillard file as well:

runfile('C:/Users/Shant/nutils/nutils/Cahn-Hillard.py', wdir='C:/Users/Shant/nutils/nutils') Traceback (most recent call last):

File "C:\Users\Shant\nutils\nutils\Cahn-Hillard.py", line 80, in from nutils.SI import Length, Time, Density, Tension, Energy, Pressure, Velocity, parse

ModuleNotFoundError: No module named 'nutils.SI'

So this is really strange and I can't seem to find the issue...

I can find the nutils files when I look into it manually, but Spyder can't seem to detect it....

joostvanzwieten commented 1 year ago

When I tried to verify the cahn-hillard script in the termal of anaconda prompt that didn't work (not sure if you meant anaconda only?)

Did you write pip install in an anaconda prompt? I don't know anaconda, so I'm not entirely sure what an anaconda prompt is. If this is an interactive Python session instead of a shell (bash, dash, powershell, etc.), then running python Cahn-Hilliard.py won't work. This is also the reason why the following didn't work.

I also put it in the terminal for Spyder and it gave me this:

python Cahn-Hilliard.py
File "C:\Users\Shant\AppData\Local\Temp\ipykernel_19008\1985523429.py", line 1
python Cahn-Hilliard.py
^
SyntaxError: invalid syntax

However, it turns out that you managed to run the Cahn-Hilliard example up to the point where it complains about the absence of some other dependency: nutils.SI:

Unfortunately I still get the same error when I run the Cahn-Hillard file as well:

runfile('C:/Users/Shant/nutils/nutils/Cahn-Hillard.py', wdir='C:/Users/Shant/nutils/nutils')
Traceback (most recent call last):

File "C:\Users\Shant\nutils\nutils\Cahn-Hillard.py", line 80, in
from nutils.SI import Length, Time, Density, Tension, Energy, Pressure, Velocity, parse

ModuleNotFoundError: No module named 'nutils.SI'

Can you run

pip install https://github.com/evalf/nutils-SI/archive/refs/heads/master.zip

just like you ran pip install nutils and try the example again? Otherwise you can try any of the other examples, as they don't depend on nutils.SI.

Shant1999 commented 1 year ago

I didn't mean to close this as completed (im new to github).

Yes I followed all the steps that was told when downloading nutils through anaconda prompt (pip install etc etc). I ran the "pip install https://github.com/evalf/nutils-SI/archive/refs/heads/master.zip", and it worked nicely:

(base) C:\Users\Shant>pip install https://github.com/evalf/nutils-SI/archive/refs/heads/master.zip Collecting https://github.com/evalf/nutils-SI/archive/refs/heads/master.zip Downloading https://github.com/evalf/nutils-SI/archive/refs/heads/master.zip

However when I run the file again on spyder I get:

runfile('C:/Users/Shant/nutils/nutils/Cahn-Hillard.py', wdir='C:/Users/Shant/nutils/nutils') Traceback (most recent call last):

File "C:\Users\Shant\nutils\nutils\Cahn-Hillard.py", line 80, in from nutils.SI import Length, Time, Density, Tension, Energy, Pressure, Velocity, parse

ModuleNotFoundError: No module named 'nutils.SI'

So for some reason my Spyder cannot recognize it... Im not sure why. Yes you are right about testing other examples as well, but I have a project on Cahn-Hillard equation and to study it, which is why I am very dedicated on solving this problem. Thank you so far for the help though, but I'm not sure what the best thing to do is..

joostvanzwieten commented 1 year ago

Can you run the following in Spyder in a (Python) console and copy the output here?

import sys, os
print('sys.path', sys.path)
print('cwd', os.getcwd())

import nutils
print('nutils', nutils.__file__)

import nutils.SI
print('nutils.SI', nutils.SI.__file__)
Shant1999 commented 1 year ago

import sys, os print('sys.path', sys.path) print('cwd', os.getcwd())

import nutils print('nutils', nutils.file)

import nutils.SI print('nutils.SI', nutils.SI.file)

gave me:

sys.path ['C:\Users\Shant\anaconda3\python39.zip', 'C:\Users\Shant\anaconda3\DLLs', 'C:\Users\Shant\anaconda3\lib', 'C:\Users\Shant\anaconda3', '', 'C:\Users\Shant\AppData\Roaming\Python\Python39\site-packages', 'C:\Users\Shant\anaconda3\lib\site-packages', 'C:\Users\Shant\anaconda3\lib\site-packages\win32', 'C:\Users\Shant\anaconda3\lib\site-packages\win32\lib', 'C:\Users\Shant\anaconda3\lib\site-packages\Pythonwin', 'C:\Users\Shant\anaconda3\lib\site-packages\IPython\extensions', 'C:\Users\Shant\.ipython'] cwd C:\Users\Shant\nutils\nutils nutils C:\Users\Shant\AppData\Roaming\Python\Python39\site-packages\nutils__init__.py nutils.SI C:\Users\Shant\AppData\Roaming\Python\Python39\site-packages\nutils\SI.py

I think I did something. I decided maybe it's best to drag the nutils.SI file into the folder manually and now when I run, I dont get that error anymore:

image

Is this what I am supposed to get and if so, where can I see the simulations?

joostvanzwieten commented 1 year ago

I think I did something. I decided maybe it's best to drag the nutils.SI file into the folder manually and now when I run, I dont get that error anymore:

If this works for you, let's keep it like this.

image

I'm a bit worried by the image you've pasted. It looks like you've copied the example into a copy of the Nutils source tree. That's potentially error-prone as Python can import packages from the current working directory (see the output of sys.path and os.getcwd() above). It's best to keep your scripts (e.g. the Cahn-Hilliard example) in a separate directory. If you've installed Nutils using pip there's no reason to have an additional copy of the source somewhere on the disk.

Is this what I am supposed to get ...

I'm afraid this is what it looks like in Spyder. In a modern Windows Terminal it should look better.

... and if so, where can I see the simulations?

At the end of the simulation the location of the HTML log is printed in the console (example console output). You can open the link with a browser.

Shant1999 commented 1 year ago

Okay it seems like the simulation was a success. Thank you a million, joost :)

joostvanzwieten commented 1 year ago

Great! I'm closing this issue now. If you encounter a different problem, please open another issue on GitHub or discuss this in our public Matrix chat room (preview).