- Thank you received: 0
Python Index Error
4 years 8 months ago #2470
by mkarkulik
Python Index Error was created by mkarkulik
Hello everybody,
I have only recently started to use NGSolve. I followed the instructions in the Documentation and compiled everything myself.
Now, I seem to have a problem with Python. For example, the Python code test.py
works fine if I call it with Python. As soon as I call it with netgen, I get the error
For example, when I uncomment the plotting routine in the python example adaptive.py, the same
thing happens. What am I doing wrong?
All the best,
Michael
I have only recently started to use NGSolve. I followed the instructions in the Documentation and compiled everything myself.
Now, I seem to have a problem with Python. For example, the Python code test.py
Code:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.show()
works fine if I call it with Python. As soon as I call it with netgen, I get the error
Code:
NETGEN-6.2-dev
Developed by Joachim Schoeberl at
2010-xxxx Vienna University of Technology
2006-2010 RWTH Aachen University
1996-2006 Johannes Kepler University Linz
optfile ./ng.opt does not exist - using default values
togl-version : 2
loading ngsolve library
NGSolve-6.2.2001-62-gaed90e28
Using Lapack
Including sparse direct solver UMFPACK
Running parallel using 4 thread(s)
importing NGSolve-6.2.2001-62-gaed90e28
(should) load python file 'test.py'
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 2811, in plot
return gca().plot(
File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 935, in gca
return gcf().gca(**kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 578, in gcf
return figure()
File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 525, in figure
**kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3218, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
File "/usr/lib/python3/dist-packages/matplotlib/backends/_backend_tk.py", line 1008, in new_figure_manager_given_figure
window = Tk.Tk(className="matplotlib")
File "/usr/lib/python3.7/tkinter/__init__.py", line 2018, in __init__
baseName = os.path.basename(sys.argv[0])
IndexError: list index out of range
Finished executing test.py
Thank you for using NGSolve
For example, when I uncomment the plotting routine in the python example adaptive.py, the same
thing happens. What am I doing wrong?
All the best,
Michael
4 years 6 months ago #2704
by dong
Replied by dong on topic Python Index Error
I think you can just call python as you did when dealing with the matplotlib error above, and then call netgen for visualizing the solution for now.
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
4 years 6 months ago #2706
by christopher
Replied by christopher on topic Python Index Error
I've had some matplotlib problems as well when using netgen gui. for me it helped to use a different backend in matplotlib, you can either do this by setting environment variables or
before importing matplotlib.pyplot.
Another option that might help is to start the gui from the python thread, run with python and do
at the start of your script. This should open the netgen gui.
Best
Christopher
Code:
import matplotlib
matplotlib.use("WXAGG")
Another option that might help is to start the gui from the python thread, run with python and do
Code:
import netgen.gui
Best
Christopher
The following user(s) said Thank You: rgs
4 years 2 months ago #3147
by larryhems
Replied by larryhems on topic Python Index Error
This error basically means you are trying to access a value at a List index which is out of bounds i.e greater than the last index of the list or less than the least index in the list. So the first element is 0, second is 1, so on. So if there are n elements in a
python list
, the last element is n-1 . If you try to access the empty or None element by pointing available index of the list, then you will get the "List index out of range " error. To solve this error, you should make sure that you're not trying to access a non-existent item in a list.
3 years 11 months ago #3422
by mkarkulik
Replied by mkarkulik on topic Python Index Error
Thank you! The first option worked. Just for reference, if you use Python 3+, you have to install
python3-wxgtk4.0
to get to change the backend.
python3-wxgtk4.0
to get to change the backend.
Time to create page: 0.112 seconds