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

Felix Dietrich felix.dietrich at sperrhaken.name
Wed Oct 26 10:12:47 EDT 2016


Ed Troy <etroy at aeroconsult.com> writes:

> I am pretty sure I installed python3. And, also, matplotlib, scipy,
> and numpy.

> How do I verify which versions of python and numpy, matplotlib and
> scipy I have installed?

The following commandline should list the version of installed python
packages required by the script – assuming you have used Ubuntu's deb
based package manager to install the scripts dependencies:

$ dpkg-query --showformat='${db:Status-Abbrev} ${binary:Package} ${Version}\n' \
--show 'python*' \
| awk '$1 ~ /.i.?/ && $2 ~ /^python3?(-((scipy)|(numpy)|(matplotlib)))?$/' \
| column -t

Short explanation: dpkg-query lists packages matching a glob-pattern;
awk filters for packages actually installed and limits the by the
glob-pattern matched package names further; column prettifies the
output.

> 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 python […]

As you have noted yourself the absence of ImportErrors strongly implies
that you have the required modules installed – even so: double checking
won't hurt.


As an aside: because the script starts with a shebang line ("#!") you do
not, after you have made it executable, need to specify the interpreter
to use, which safes you the trouble of choosing Version 2 or 3 of python
(or mistyping the interpreter name) and would also allow the script to
be easily called from a directory in your PATH environment variable:

$ chmod u+x LED_model_utf8.py
$ ./LED_model_utf8.py LED_model_utf8.py LED_IV.txt

--
Felix Dietrich




More information about the Tutor mailing list