Re: [Tutor] Finding the version # of a module, and py module problem

Discussion in 'Python' started by W. eWatson, Aug 6, 2010.

  1. W. eWatson

    W. eWatson Guest

    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
    W. eWatson, Aug 6, 2010
    #1
    1. Advertising

  2. Re: [Tutor] Finding the version # of a module, and py moduleproblem

    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
    Steven D'Aprano, Aug 6, 2010
    #2
    1. Advertising

  3. W. eWatson

    MRAB Guest

    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".
    MRAB, Aug 6, 2010
    #3
  4. W. eWatson

    W. eWatson Guest

    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.
    W. eWatson, Aug 6, 2010
    #4
  5. W. eWatson

    W. eWatson Guest

    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.
    W. eWatson, Aug 6, 2010
    #5
  6. 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
    Philip Semanchuk, Aug 6, 2010
    #6
  7. 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
    Richard D. Moores, Aug 6, 2010
    #7
  8. 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
    Philip Semanchuk, Aug 6, 2010
    #8
  9. W. eWatson

    W. eWatson Guest

    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, Aug 6, 2010
    #9
  10. W. eWatson

    W. eWatson Guest

    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'
    W. eWatson, Aug 6, 2010
    #10
  11. 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.

    > http://mail.python.org/mailman/listinfo/python-list
    >
    Benjamin Kaplan, Aug 6, 2010
    #11
  12. 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
    Philip Semanchuk, Aug 7, 2010
    #12
  13. W. eWatson

    W. eWatson Guest

    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, ...?
    W. eWatson, Aug 7, 2010
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. administrata

    problem with tutor mailing

    administrata, Feb 16, 2005, in forum: Python
    Replies:
    3
    Views:
    293
    Kartic
    Feb 16, 2005
  2. Shawn Milochik

    Re: [Tutor] Finding prime numbers

    Shawn Milochik, Sep 19, 2007, in forum: Python
    Replies:
    4
    Views:
    283
    Shawn Milochik
    Sep 20, 2007
  3. V Green
    Replies:
    0
    Views:
    829
    V Green
    Feb 5, 2008
  4. PA Bear [MS MVP]
    Replies:
    0
    Views:
    932
    PA Bear [MS MVP]
    Feb 5, 2008
  5. MowGreen [MVP]
    Replies:
    5
    Views:
    2,001
    PA Bear [MS MVP]
    Feb 9, 2008
Loading...

Share This Page