FAQ
It's been awhile since I've used python, and I recall there is a way to
find the version number from the IDLE command line prompt. dir, help,
__version.__?

I made the most minimal change to a program, and it works for me, but
not my partner. He gets

Traceback (most recent call last):
File "C:\Documents and
Settings\HP_Administrator.DavesDesktop\Desktop\NC-FireballReport20100729.py",
line 40, in <module>
from scipy import stats as stats # scoreatpercentile
File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7,
in <module>
from stats import *
File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191,
in <module>
import scipy.special as special
File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line
22, in <module>
from numpy.testing import NumpyTest
ImportError: cannot import name NumpyTest

Here are the first few lines of code.

import sys, os, glob
import string
from numpy import *
from datetime import datetime, timedelta
import time
from scipy import stats as stats # scoreatpercentile

I'm pretty sure he has the same version of Python, 2.5, but perhaps not
the numpy or scipy modules. I need to find out his version numbers.

--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet

Search Discussions

  • Steven D'Aprano at Aug 6, 2010 at 1:13 am

    On Thu, 05 Aug 2010 17:55:30 -0700, W. eWatson wrote:

    I'm pretty sure he has the same version of Python, 2.5, but perhaps not
    the numpy or scipy modules. I need to find out his version numbers.
    It's only a convention, but the usual way is to check the __version__
    attribute. It works for Numpy:
    import numpy
    numpy.__version__
    '1.0.3'



    --
    Steven
  • W. eWatson at Aug 6, 2010 at 1:40 am

    On 8/5/2010 6:13 PM, Steven D'Aprano wrote:
    On Thu, 05 Aug 2010 17:55:30 -0700, W. eWatson wrote:

    I'm pretty sure he has the same version of Python, 2.5, but perhaps not
    the numpy or scipy modules. I need to find out his version numbers.
    It's only a convention, but the usual way is to check the __version__
    attribute. It works for Numpy:
    import numpy
    numpy.__version__
    '1.0.3'

    It is now written in my Py book. Thanks.
  • MRAB at Aug 6, 2010 at 1:23 am

    W. eWatson wrote:
    It's been awhile since I've used python, and I recall there is a way to
    find the version number from the IDLE command line prompt. dir, help,
    __version.__?

    I made the most minimal change to a program, and it works for me, but
    not my partner. He gets

    Traceback (most recent call last):
    File "C:\Documents and
    Settings\HP_Administrator.DavesDesktop\Desktop\NC-FireballReport20100729.py",
    line 40, in <module>
    from scipy import stats as stats # scoreatpercentile
    File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7,
    in <module>
    from stats import *
    File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191,
    in <module>
    import scipy.special as special
    File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line
    22, in <module>
    from numpy.testing import NumpyTest
    ImportError: cannot import name NumpyTest

    Here are the first few lines of code.

    import sys, os, glob
    import string
    from numpy import *
    from datetime import datetime, timedelta
    import time
    from scipy import stats as stats # scoreatpercentile

    I'm pretty sure he has the same version of Python, 2.5, but perhaps not
    the numpy or scipy modules. I need to find out his version numbers.
    Try:

    import numpy
    help(numpy.version)

    BTW, on Python 2.6 I can see that there's "numpytest" but not
    "NumpyTest".
  • W. eWatson at Aug 6, 2010 at 1:42 am

    On 8/5/2010 6:23 PM, MRAB wrote:
    W. eWatson wrote:
    It's been awhile since I've used python, and I recall there is a way
    to find the version number from the IDLE command line prompt. dir,
    help, __version.__?

    I made the most minimal change to a program, and it works for me, but
    not my partner. He gets

    Traceback (most recent call last):
    File "C:\Documents and
    Settings\HP_Administrator.DavesDesktop\Desktop\NC-FireballReport20100729.py",
    line 40, in <module>
    from scipy import stats as stats # scoreatpercentile
    File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7,
    in <module>
    from stats import *
    File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191,
    in <module>
    import scipy.special as special
    File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line
    22, in <module>
    from numpy.testing import NumpyTest
    ImportError: cannot import name NumpyTest

    Here are the first few lines of code.

    import sys, os, glob
    import string
    from numpy import *
    from datetime import datetime, timedelta
    import time
    from scipy import stats as stats # scoreatpercentile

    I'm pretty sure he has the same version of Python, 2.5, but perhaps
    not the numpy or scipy modules. I need to find out his version numbers.
    Try:

    import numpy
    help(numpy.version)

    BTW, on Python 2.6 I can see that there's "numpytest" but not
    "NumpyTest".
    I have to stick with 2.5 for comparability with my partner. He's
    non-Python but was able to get Python 2.5 working. I think he somehow
    bumped ahead to a later version of numpy than I have.
  • Philip Semanchuk at Aug 6, 2010 at 1:47 am

    On Aug 5, 2010, at 8:55 PM, W. eWatson wrote:

    It's been awhile since I've used python, and I recall there is a way
    to find the version number from the IDLE command line prompt. dir,
    help, __version.__?
    Hi Wayne,
    FYI it's got nothing to do with IDLE, it's just a question of whether
    or not the module in question exposes any kind of a version attribute.
    There's no standard, unfortunately. The most popular convention seems
    to be via an attribute called __version__, but I've also seen
    __VERSION__, VERSION, and version.

    Here's some code that I wrote that you might find useful. It's from a
    setup.py and it checks a list of modules on which our project depends
    to see if (a) they're installed and (b) if the version installed is
    adequate. In the snippet below, dependencies is a list of custom
    classes that represent modules we need (e.g. numpy).


    # Try each module
    for dependency in dependencies:
    try:
    __import__(dependency.name)
    except ImportError:
    # Uh oh!
    dependency.installed = None
    else:
    # The module loaded OK. Get a handle to it and try to
    extract
    # version info.
    # Many Python modules follow the convention of providing
    their
    # version as a string in a __version__ attribute.
    module = sys.modules[dependency.name]

    # This is what I default to.
    dependency.installed = "[version unknown]"

    for attribute_name in ("__version__", "__VERSION__",
    "VERSION",
    "version"):
    if hasattr(module, attribute_name):
    dependency.installed = getattr(module,
    attribute_name)
    break

    Hope this helps a little,
    Philip
  • Richard D. Moores at Aug 6, 2010 at 2:20 pm

    On Thu, Aug 5, 2010 at 18:47, Philip Semanchuk wrote:
    it's just a question of whether or not
    the module in question exposes any kind of a version attribute. There's no
    standard, unfortunately. The most popular convention seems to be via an
    attribute called __version__, but I've also seen __VERSION__, VERSION, and
    version.
    Here's one more way:
    import gmpy
    gmpy.__version__
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute '__version__'
    gmpy.version()
    '1.12'
    >>>

    Dick Moores
  • Philip Semanchuk at Aug 6, 2010 at 3:09 pm

    On Aug 6, 2010, at 10:20 AM, Richard D. Moores wrote:

    On Thu, Aug 5, 2010 at 18:47, Philip Semanchuk
    wrote:
    it's just a question of whether or not
    the module in question exposes any kind of a version attribute.
    There's no
    standard, unfortunately. The most popular convention seems to be
    via an
    attribute called __version__, but I've also seen __VERSION__,
    VERSION, and
    version.
    Here's one more way:
    import gmpy
    gmpy.__version__
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute '__version__'
    gmpy.version()
    '1.12'
    That's the nice thing about standards -- there are so many to choose
    from! =)

    Thanks for pointing that out; I'll update my code.

    bye
    Philip
  • W. eWatson at Aug 6, 2010 at 5:54 pm

    On 8/5/2010 6:47 PM, Philip Semanchuk wrote:
    On Aug 5, 2010, at 8:55 PM, W. eWatson wrote:

    It's been awhile since I've used python, and I recall there is a way
    to find the version number from the IDLE command line prompt. dir,
    help, __version.__?
    Hi Wayne,
    FYI it's got nothing to do with IDLE, it's just a question of whether or
    not the module in question exposes any kind of a version attribute.
    There's no standard, unfortunately. The most popular convention seems to
    be via an attribute called __version__, but I've also seen __VERSION__,
    VERSION, and version.

    Here's some code that I wrote that you might find useful. It's from a
    setup.py and it checks a list of modules on which our project depends to
    see if (a) they're installed and (b) if the version installed is
    adequate. In the snippet below, dependencies is a list of custom classes
    that represent modules we need (e.g. numpy).


    # Try each module
    for dependency in dependencies:
    try:
    __import__(dependency.name)
    except ImportError:
    # Uh oh!
    dependency.installed = None
    else:
    # The module loaded OK. Get a handle to it and try to extract
    # version info.
    # Many Python modules follow the convention of providing their
    # version as a string in a __version__ attribute.
    module = sys.modules[dependency.name]

    # This is what I default to.
    dependency.installed = "[version unknown]"

    for attribute_name in ("__version__", "__VERSION__", "VERSION",
    "version"):
    if hasattr(module, attribute_name):
    dependency.installed = getattr(module, attribute_name)
    break

    Hope this helps a little,
    Philip
    Thanks. I'll look into it.
  • W. eWatson at Aug 6, 2010 at 7:14 pm
    I must be missing something. I tried this. (Windows, IDLE, Python 2.5)
    # Try each module
    import sys
    import numpy
    import scipy
    import string

    dependencies = "numyp", "scipy"
    for dependency in dependencies:
    try:
    __import__(dependency.name)
    except ImportError:
    # Uh oh!
    dependency.installed = None
    else:
    # The module loaded OK. Get a handle to it and try to extract
    # version info.
    # Many Python modules follow the convention of providing their
    # version as a string in a __version__ attribute.
    module = sys.modules[dependency.name]

    # This is what I default to.
    dependency.installed = "[version unknown]"

    for attribute_name in ("__version__", "__VERSION__", "VERSION",
    "version"):
    if hasattr(module, attribute_name):
    dependency.installed = getattr(module, attribute_name)
    break

    The result was this.
    Traceback (most recent call last):
    File
    "C:/Users/Wayne/Sandia_Meteors/Trajectory_Estimation/dependency_code",
    line 10, in <module>
    __import__(dependency.name)
    AttributeError: 'str' object has no attribute 'name'
  • Benjamin Kaplan at Aug 6, 2010 at 7:28 pm

    On Fri, Aug 6, 2010 at 12:14 PM, W. eWatson wrote:
    I must be missing something. I tried this. (Windows, IDLE, Python 2.5)
    # Try each module
    import sys
    import numpy
    import scipy
    import string

    dependencies = "numyp", "scipy"
    for dependency in dependencies:
    ? ?try:
    ? ? ? ?__import__(dependency.name)
    ? ?except ImportError:
    ? ? ? ?# Uh oh!
    ? ? ? ?dependency.installed = None
    ? ?else:
    ? ? ? ?# The module loaded OK. Get a handle to it and try to extract
    ? ? ? ?# version info.
    ? ? ? ?# Many Python modules follow the convention of providing their
    ? ? ? ?# version as a string in a __version__ attribute.
    ? ? ? ?module = sys.modules[dependency.name]

    ? ? ? ?# This is what I default to.
    ? ? ? ?dependency.installed = "[version unknown]"

    ? ? ? ?for attribute_name in ("__version__", "__VERSION__", "VERSION",
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "version"):
    ? ? ? ? ? ?if hasattr(module, attribute_name):
    ? ? ? ? ? ? ? ?dependency.installed = getattr(module, attribute_name)
    ? ? ? ? ? ? ? ?break

    The result was this.
    Traceback (most recent call last):
    ?File "C:/Users/Wayne/Sandia_Meteors/Trajectory_Estimation/dependency_code",
    line 10, in <module>
    ? ?__import__(dependency.name)
    AttributeError: 'str' object has no attribute 'name'
    --
    Try reading the code, not just copying and pasting. dependencies isn't
    supposed to be a list of strings. It's a list of objects (at least) a
    name and an installed attribute.
  • Tommy Grav at Aug 6, 2010 at 7:31 pm

    On Aug 6, 2010, at 3:14 PM, W. eWatson wrote:

    I must be missing something. I tried this. (Windows, IDLE, Python 2.5)
    # Try each module
    import sys
    import numpy
    import scipy
    import string

    dependencies = "numyp", "scipy"
    for dependency in dependencies:
    try:
    __import__(dependency.name)
    except ImportError:
    # Uh oh!
    dependency.installed = None
    else:
    # The module loaded OK. Get a handle to it and try to extract
    # version info.
    # Many Python modules follow the convention of providing their
    # version as a string in a __version__ attribute.
    module = sys.modules[dependency.name]

    # This is what I default to.
    dependency.installed = "[version unknown]"

    for attribute_name in ("__version__", "__VERSION__", "VERSION",
    "version"):
    if hasattr(module, attribute_name):
    dependency.installed = getattr(module, attribute_name)
    break

    The result was this.
    Traceback (most recent call last):
    File "C:/Users/Wayne/Sandia_Meteors/Trajectory_Estimation/dependency_code", line 10, in <module>
    __import__(dependency.name)
    AttributeError: 'str' object has no attribute 'name'
    --
    http://mail.python.org/mailman/listinfo/python-list
    dependencies = "numpy", "scipy"

    is a tuple of two strings, when you do your for loop you
    first get "numpy" (a string) and it does not have a .name
    attribute.

    Tommy
  • Philip Semanchuk at Aug 7, 2010 at 2:18 am

    On Aug 6, 2010, at 3:14 PM, W. eWatson wrote:

    I must be missing something. I tried this. (Windows, IDLE, Python 2.5)
    Yes, as Benjamin Kaplan pointed out and as I said in the email where I
    posted this code snippet, "dependencies is a list of custom classes
    that represent modules we need (e.g. numpy)." The code I posted was
    not meant to be a complete working example. It's part of a larger
    piece of code that I didn't have time to cook down to a simpler, self-
    sufficient whole.

    Also, in your list you've got "numyp" instead of "numpy".

    Also, at the top of your code you have "import numpy" and "import
    scipy" which defeats the purpose of this code.

    Try this (untested):
    import sys

    dependencies = ("numpy", "scipy", "some_other_module")
    for dependency in dependencies:
    try:
    __import__(dependency)
    except ImportError:
    # Uh oh!
    print "%s is not installed" % dependency
    else:
    # The module loaded OK. Get a handle to it and try to extract
    # version info.
    # Many Python modules follow the convention of providing their
    # version as a string in a __version__ attribute.
    module = sys.modules[dependency]

    for attribute_name in ("__version__", "__VERSION__", "VERSION",
    "version"):
    if hasattr(module, attribute_name):
    version = getattr(module, attribute_name)
    print "module %s has version %s" % (dependency, version)
    break



    bye
    Philip



    # Try each module
    import sys
    import numpy
    import scipy
    import string

    dependencies = "numyp", "scipy"
    for dependency in dependencies:
    try:
    __import__(dependency.name)
    except ImportError:
    # Uh oh!
    dependency.installed = None
    else:
    # The module loaded OK. Get a handle to it and try to extract
    # version info.
    # Many Python modules follow the convention of providing their
    # version as a string in a __version__ attribute.
    module = sys.modules[dependency.name]

    # This is what I default to.
    dependency.installed = "[version unknown]"

    for attribute_name in ("__version__", "__VERSION__", "VERSION",
    "version"):
    if hasattr(module, attribute_name):
    dependency.installed = getattr(module, attribute_name)
    break

    The result was this.
    Traceback (most recent call last):
    File "C:/Users/Wayne/Sandia_Meteors/Trajectory_Estimation/
    dependency_code", line 10, in <module>
    __import__(dependency.name)
    AttributeError: 'str' object has no attribute 'name'
    --
    http://mail.python.org/mailman/listinfo/python-list
  • W. eWatson at Aug 7, 2010 at 4:12 pm

    On 8/6/2010 7:18 PM, Philip Semanchuk wrote:
    On Aug 6, 2010, at 3:14 PM, W. eWatson wrote:

    I must be missing something. I tried this. (Windows, IDLE, Python 2.5)
    Yes, as Benjamin Kaplan pointed out and as I said in the email where I
    posted this code snippet, "dependencies is a list of custom classes that
    represent modules we need (e.g. numpy)." The code I posted was not meant
    to be a complete working example. It's part of a larger piece of code
    that I didn't have time to cook down to a simpler, self-sufficient whole.

    Also, in your list you've got "numyp" instead of "numpy".

    Also, at the top of your code you have "import numpy" and "import scipy"
    which defeats the purpose of this code.
    Good. It worked. Are there other attributes of a module that can help
    identify it further? Release date, ...?

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 6, '10 at 12:55a
activeAug 7, '10 at 4:12p
posts14
users7
websitepython.org

People

Translate

site design / logo © 2022 Grokbase