[Tutor] What is wrong with my Python program that causes it to run but not give results?

2016-10-25 Thread Ed Troy
I found a very useful Python program for calculating the Spice 
parameters for a LED. I have Python3 and the various modules loaded onto 
my Ubuntu machine. I created the diode IV curve data as per the article, 
but I can't seem to get it to run. My python filename is 
LED_model_utf8.py  The text file with the LED IV data is LED_IV.txt.


When I type python LED_model_utf8.py LED_IV.txt, I get an error message:
edward@ubuntu:~$ python LED_model_utf8.py LED_IV.txt
Traceback (most recent call last):
  File "LED_model_utf8.py", line 4, in 
import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot


If I type python3 LED_model_utf8.py LED_IV.txt, there is a pause and 
then I am back to the $ prompt. So, it seems like the program is 
running, but I am not getting any results like graphs and Spice 
parameters. Clearly, something is wrong, although the program "seems" to 
run correctly without errors. It just does not "do" anything.


The page that contains the file and a description of how it works is:
https://leicesterraspberrypi.wordpress.com/projects/modelling-a-diode-for-use-in-spice-simulations/

I can attach or list out my python file and the data file if needed.
Ed


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is wrong with my Python program that causes it to run but not give results?

2016-10-26 Thread Ed Troy
I am pretty sure I installed python3. And, also, matplotlib, scipy, and 
numpy. If I enter either python or python3, I get the >>>  prompt, so I 
may have both installed. How do I verify which versions of python and 
numpy, matplotlib and scipy I have installed? I am pretty sure I have 
matplotlib, scipy, and numpy installed under python3, especially since I 
don't get an error message when I run the program using python3, but, I 
don't get any output, either, so something is wrong.


Would it be a help if I actually list the python program that I am 
trying to run?


On 10/25/2016 7:50 PM, Alan Gauld via Tutor wrote:

On 25/10/16 20:24, Ed Troy wrote:


my Ubuntu machine. I created the diode IV curve data as per the article,
but I can't seem to get it to run.
edward@ubuntu:~$ python LED_model_utf8.py LED_IV.txt
Traceback (most recent call last):
File "LED_model_utf8.py", line 4, in 
  import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot

Plain 'python' on Ubuntu usually runs Python v2.
It looks like you don;t have Matplotlib inastalled for Python 2.
Matplotlib is part of the 3rd party SciPy libraries and not
part of the standard python install.

Having looked at the web page it seems you need to use python3
and have scipy, numpy and matplotlib packages installed.
You should have them in your software centre as
python3-scipy, python3-numpy and python3-matplotlib


If I type python3 LED_model_utf8.py LED_IV.txt, there is a pause and
then I am back to the $ prompt. So, it seems like the program is
running, but I am not getting any results

That's correct. But without seeing the code and data it's
hard to guess but you could at least verify that it runs
by editing the python file to include print lines.
Go to the end of the file and modify the last segment
to look like:


if __name__ == "__main__":
   print("Starting")
   main()
   print("Stopping...")



The page that contains the file and a description of how it works is:
https://leicesterraspberrypi.wordpress.com/projects/modelling-a-diode-for-use-in-spice-simulations/

I see the code but I don't see a path that
doesn't print anything... You should see some
kind of output.




--
RF, Microwave, Antenna, and Analog Design,
Development,Simulation, and Research Consulting
http://aeroconsult.com
Aerospace Consulting LLC
P.O. Box 536
Buckingham, Pa. 18912
(215) 345-7184
(215) 345-1309 FAX

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is wrong with my Python program that causes it to run but not give results?

2016-10-26 Thread Ed Troy
I found the problem. Originally, I was getting errors that were related 
to formatting, apparently. It looked fine to me, but because I had 
copied it from the web, there were, apparently, hidden characters. In an 
effort to get rid of errors, I was eliminating some lines. I finally 
added a line,

# -#- coding: utf-8 -*-
near the beginning of the file. This is when I got to where I was with 
it seeming to run if I started the command line with python3 but getting 
errors if I started with python. I was pretty sure I had all of the 
required modules installed.


But then, when instructed to add some lines at the end for debugging, I 
found that I had accidentally removed two lines at the end and forgot to 
add them back in.


They were:
if __name__=="__main__":
main()

Once I added them, it runs fine whether I say python LED_model_utf8.py 
LED_IV.txt or python3 LED_model_utf8.py LED_IV.txt


Thanks to everyone. Sorry for the mistake on my part. I think that if I 
had added the # -#- coding: utf-8 -*- right from the start, the problem 
never would have happened.

Ed

On 10/26/2016 10:18 AM, Felix Dietrich wrote:

Alan Gauld via Tutor  writes:

On 26/10/16 04:19, Ed Troy wrote:
Would it be a help if I actually list the python program that I am
trying to run?

Yes. I'm assuming you just cut n paste the code from the web site but
something could have gone wrong with the formatting and Python is
sensitive to that, so seeing your actual code would be a good idea.

Could you also provide a small set of sample data that fails, maybe

 $ head LED_IV.txt > sample.txt

will be enough.

--
Felix Dietrich
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor