classification
Title: Unable to import random with python2.7 on power pc based machine
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: cheryl.sabella, mark.dickinson, ragreddy, rhettinger, serhiy.storchaka, skrah, vstinner
Priority: normal Keywords:

Created on 2016-04-13 00:56 by ragreddy, last changed 2018-02-14 07:34 by mark.dickinson. This issue is now closed.

Files
File name Uploaded Description Edit
sqrt.c vstinner, 2016-04-14 00:45
Messages (29)
msg263292 - (view) Author: Raghu (ragreddy) Date: 2016-04-13 00:56
Hi, I am trying to import random on a power pc based machine and I see this exception. Could you please help me?

root@host# python
Python 2.7.3 (default, Apr  3 2016, 22:31:30)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/random.py", line 58, in <module>
    NV_MAGICCONST = 4 * _exp(-0.5)/_sqrt(2.0)
ValueError: math domain error
>>>
msg263309 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-04-13 05:54
That's odd.

Try:
   import math
   print math.sqrt(2.0)
   print math

Post what you see.
msg263327 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2016-04-13 11:35
The output of `struct.pack('<d', 2.0)` would also be worth knowing about. I'm wondering whether there's some kind of endianness issue going on in the float-to-string conversions.
msg263360 - (view) Author: Raghu (ragreddy) Date: 2016-04-13 21:13
Hi, I apologize. I didn't expect a quick reply.
Here are the outputs you requested.

root@host:~# python
Python 2.7.3 (default, Apr  3 2016, 22:31:30)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> print math.sqrt(2.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error
>>> print math
<module 'math' from '/usr/lib/python2.7/lib-dynload/math.so'>
>>> import struct
>>> struct.pack('<d', 2.0)
'\x00\x00\x00\x00\x00\x00\x00@'
>>>
msg263362 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-04-14 00:45
>>> print math.sqrt(2.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error

I'm surprised that such basic math function fails.

Can you please try to compile and run attached C program?

$ gcc sqrt.c -o sqrt -lm && ./sqrt
sqrt(2) = 1.41421
msg263363 - (view) Author: Raghu (ragreddy) Date: 2016-04-14 00:48
stinner victor, my host doesn't have a gcc compiler. is there a way you can give me the binary?
msg263364 - (view) Author: Raghu (ragreddy) Date: 2016-04-14 00:50
my host details:

Linux fpc0 3.10.62-ltsi-WR6.0.0.18_standard #1 SMP PREEMPT Sun Apr 3 23:17:02 PDT 2016 ppc64 ppc64 ppc64 GNU/Linux
msg263365 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-04-14 01:04
What is your Linux distribution and what is your CPU? (try to read /proc/cpuinfo)

You cannot install a C compiler?
msg263366 - (view) Author: Raghu (ragreddy) Date: 2016-04-14 01:14
It's windriver linux. Processor is PPC64-E5500
msg263369 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-14 04:35
What is the output of `struct.pack('d', 2.0)` and `struct.pack('d', float(2))`?
msg263370 - (view) Author: Raghu (ragreddy) Date: 2016-04-14 05:43
Serhiy,

root@host:~# python
Python 2.7.3 (default, Apr  3 2016, 22:31:30)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> struct.pack('d', 2.0)
'@\x00\x00\x00\x00\x00\x00\x00'
>>> struct.pack('d', float(2))
'@\x00\x00\x00\x00\x00\x00\x00'
>>>
msg263373 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-14 07:35
What is the output of `python -m sysconfig`?

Python 2.7.3 is too old. May be this issue was already fixed in newer versions. Can you install 2.7.11?
msg263376 - (view) Author: Raghu (ragreddy) Date: 2016-04-14 07:43
There is no output for `python -m sysconfig`
msg263379 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-14 08:09
What is the output of `import sysconfig; print sysconfig.get_config_vars()`?
msg263428 - (view) Author: Raghu (ragreddy) Date: 2016-04-14 18:52
Hi, This is my work system and I don't know if I am allowed to send out the complete output of "print sysconfig.get_config_vars()". could you please let me know which fields you are looking for?
msg263429 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-14 19:13
Fields with ENDIAN or IEEE in key.
msg263431 - (view) Author: Raghu (ragreddy) Date: 2016-04-14 22:18
The keys ENDIAN and IEEE are not available.
msg263432 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-04-14 22:26
I guess that Serhiy is looking for these variables defined in pyconfig.h:
---
/* Define if C doubles are 64-bit IEEE 754 binary format, stored in ARM
   mixed-endian order (byte order 45670123) */
#undef DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754

/* Define if C doubles are 64-bit IEEE 754 binary format, stored with the most
   significant byte first */
#undef DOUBLE_IS_BIG_ENDIAN_IEEE754

/* Define if C doubles are 64-bit IEEE 754 binary format, stored with the
   least significant byte first */
#undef DOUBLE_IS_LITTLE_ENDIAN_IEEE754
---

On Fedora, pyconfig.h is installed into /usr/include/python2.7/pyconfig.h. This file doesn't contain any sensitive information, it is the configuration used to build Python.

On Fedora, this file only dispatches between pyconfig-32.h and pyconfig-64.h:
---
$ cat /usr/include/python2.7/pyconfig.h 
#include <bits/wordsize.h>

#if __WORDSIZE == 32
#include "pyconfig-32.h"
#elif __WORDSIZE == 64
#include "pyconfig-64.h"
#else
#error "Unknown word size"
#endif
---

My system is 64-bit, so I can use pyconfig-64.h:
---
$ grep IEEE /usr/include/python2.7/pyconfig-64.h 
/* Define if C doubles are 64-bit IEEE 754 binary format, stored in ARM
/* #undef DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754 */
/* Define if C doubles are 64-bit IEEE 754 binary format, stored with the most
/* #undef DOUBLE_IS_BIG_ENDIAN_IEEE754 */
/* Define if C doubles are 64-bit IEEE 754 binary format, stored with the
#define DOUBLE_IS_LITTLE_ENDIAN_IEEE754 1
/* #undef HAVE_IEEEFP_H */
/* #undef HAVE_LIBIEEE */
/* Define to activate features from IEEE Stds 1003.1-2001 */
---
msg263433 - (view) Author: Raghu (ragreddy) Date: 2016-04-14 23:11
Here is one output:

root@fpc0:~# grep IEEE /usr/include/python2.7/pyconfig-32.h
/* Define if C doubles are 64-bit IEEE 754 binary format, stored in ARM
/* #undef DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754 */
/* Define if C doubles are 64-bit IEEE 754 binary format, stored with the most
/* #undef DOUBLE_IS_BIG_ENDIAN_IEEE754 */
/* Define if C doubles are 64-bit IEEE 754 binary format, stored with the
/* #undef DOUBLE_IS_LITTLE_ENDIAN_IEEE754 */
/* #undef HAVE_IEEEFP_H */
/* #undef HAVE_LIBIEEE */
/* Define to activate features from IEEE Stds 1003.1-2001 */
root@fpc0:~#
msg263435 - (view) Author: Raghu (ragreddy) Date: 2016-04-14 23:28
Couple more outputs:

----------------
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
   significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
#  define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
#  define WORDS_BIGENDIAN 1
# endif
#endif
----------------

Math works in some cases.
----------------
>>> import math
>>> math.sqrt(2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error
>>> math.floor(2.5)
2.0
>>>
----------------


Also, could you please let me know the train of thought and ask for all the outputs as much as possible in one go? because I feel like I am delaying your debugging.
msg263436 - (view) Author: Raghu (ragreddy) Date: 2016-04-14 23:39
@stinner, my host doesn't have internet connection and it doesn't have gcc installed.

I don't know how to install gcc in windriverlinux.
In famous linux distributions like ubuntu and centos, i install gcc using 'yum install gcc' or 'apt-get install gcc' commands.
msg263513 - (view) Author: Raghu (ragreddy) Date: 2016-04-15 18:26
Hey Guys/Gals, are you still debugging the issue? Do you need more info?
msg263514 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-04-15 18:40
An option would be to use the support of the probably commercial

  http://www.windriver.com/products/linux/

and ask them why they're still on Python 2.7.3.  They'll also
have gcc installed and can run the test case proposed in this
issue.
msg263516 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-04-15 19:01
Also, I don't understand how the test suite could pass with
these kinds of errors. Are you sure this is the Wind-River
system Python?  Did they run the test suite?
msg263526 - (view) Author: Raghu (ragreddy) Date: 2016-04-15 21:04
Yes, it is a WindRiver linux. I will check if Commercial WindRiver team can help me.

Host details:
Linux fpc0 3.10.62-ltsi-WR6.0.0.18_standard #1 SMP PREEMPT Sun Apr 3 23:17:02 PDT 2016 ppc64 ppc64 ppc64 GNU/Linux



Also is there a protocol followed in this website? If I have done something wrong it's because I didn't know I was doing it incorrectly. I ask because, a new person replies everyday and they don't even completely tell me the solution or what conclusions they have made. I am lost.
msg263527 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-04-15 21:29
My conclusion is:  The error in msg263292 should have been
caught by the test suite.

I'd ask the WindRiver support if they actually run the test suite
before shipping the binaries.
msg263528 - (view) Author: Raghu (ragreddy) Date: 2016-04-15 21:32
Thank you skrah. I raised a support request from WR. I will keep my fingers crossed.
msg312146 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-02-14 00:22
Since there hasn't been activity on this for nearly 2 years, should it be closed as third party?  Stefan seemed to conclude that it was a WindRiver issue.  Thanks!
msg312162 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2018-02-14 07:34
@csabella: Agreed. Let's close. Thanks!
History
Date User Action Args
2018-02-14 07:34:47mark.dickinsonsetstatus: open -> closed
resolution: third party
messages: + msg312162

stage: resolved
2018-02-14 00:22:39cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg312146
2016-04-15 21:32:00ragreddysetmessages: + msg263528
2016-04-15 21:29:00skrahsetmessages: + msg263527
2016-04-15 21:04:26ragreddysetmessages: + msg263526
2016-04-15 19:01:36skrahsetmessages: + msg263516
2016-04-15 18:40:08skrahsetnosy: + skrah
messages: + msg263514
2016-04-15 18:26:15ragreddysetmessages: + msg263513
2016-04-14 23:39:07ragreddysetmessages: + msg263436
2016-04-14 23:28:55ragreddysetmessages: + msg263435
2016-04-14 23:11:24ragreddysetmessages: + msg263433
2016-04-14 22:26:41vstinnersetmessages: + msg263432
2016-04-14 22:18:56ragreddysetmessages: + msg263431
2016-04-14 19:13:56serhiy.storchakasetmessages: + msg263429
2016-04-14 18:52:00ragreddysetmessages: + msg263428
2016-04-14 08:09:52serhiy.storchakasetmessages: + msg263379
2016-04-14 07:43:43ragreddysetmessages: + msg263376
2016-04-14 07:35:16serhiy.storchakasetmessages: + msg263373
2016-04-14 05:43:15ragreddysetmessages: + msg263370
2016-04-14 04:35:47serhiy.storchakasetmessages: + msg263369
2016-04-14 01:14:34ragreddysetmessages: + msg263366
2016-04-14 01:04:03vstinnersetmessages: + msg263365
2016-04-14 00:50:28ragreddysetmessages: + msg263364
2016-04-14 00:48:53ragreddysetmessages: + msg263363
2016-04-14 00:45:12vstinnersetfiles: + sqrt.c
nosy: + vstinner
messages: + msg263362

2016-04-13 21:13:26ragreddysetmessages: + msg263360
2016-04-13 11:35:46mark.dickinsonsetmessages: + msg263327
2016-04-13 05:54:13rhettingersetmessages: + msg263309
2016-04-13 05:15:41serhiy.storchakasetnosy: + rhettinger, mark.dickinson, serhiy.storchaka
type: crash -> behavior
2016-04-13 00:56:46ragreddycreate