OS major build number in Linux Machine - python-3.x

In Python, how to fetch OS Major build number for Linux and Windows.
Below code can give us the Major Windows build number under version parameter.
>>> import platform; platform.uname()
uname_result(system='Windows', node='LP-213289619', release='10', version='10.0.22621', machine='AMD64')
Major Windows OS Build Number -> 22621
What is the equivalent value for Linux when we execute same code in Linux.
>>> import platform; platform.uname()
uname_result(system='Linux', node='ubuntu', release='4.15.0-202-generic', version='#213-Ubuntu SMP Thu Jan 5 19:19:12 UTC 2023', machine='x86_64', processor='x86_64')
Major Linux OS Build Number -> ?
Or any other common way to print OS build number for both Linux and Windows.

Related

How to fix Python error "...failed to map segment from shared object" appearing when I try to import NumPy library on GCP?

I've recently started to use Google Cloud Platform and I run my python scripts in Cloud Shell within Linux environment.
By running one of the scripts that is using pandas library I ran into very unpleasant error which is:
Traceback (most recent call last):
File "pandas_excercises.py", line 1, in <module>
import pandas as pd
File "/home/dann_frol/.local/lib64/python3.6/site-packages/pandas/__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.6 from "/usr/bin/python3"
* The NumPy version is: "1.19.0"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: /home/dann_frol/.local/lib64/python3.6/site-packages/numpy/core/_multiarray_umath.cpython-36m-x86_64-linux-gnu.so: failed to map segment from shared object
I've checked both python and numpy versions and they seem to match to the ones described in the error message.
I've tried to reinstall both pandas and numpy using python3 -m pip uninstall pandas and python3 -m pip install pandas , however it didn't help.
When I run the code, I use the following command: python3 pandas_excercises.py
Some info about the OS:
Operating System: Container-Optimized OS from Google
Kernel: Linux 4.19.114+
Architecture: x86-64
What could be the possible issue and how to fix this error?
Thank you, any help is appreciated.
I'm pretty sure that in case of Python libraries' natives, the message failed to map segment from shared object means that the .so file isn't marked executable. (ls -l says e.g. -rw-r--r-- instead of -rwxr-xr-x.)
The only way (that I can think of) how it can be so after a sane pip install is if filesystem is mounted with noexec flag. (Which was the case on my setup.) You can quickly check for it using mount command, it will be listed among other flags inside braces if it is set.
How to remove that noexec flag is another question.
Container-Optimized OS (COS) has several limitations that could be a reason that your program does not work.
COS is an operating system optimized for running Docker containers. But it lacks many of components you have in a typical Linux distribution. This distribution components and especially a kernel are quite different from the generic Linux installation.
Container-Optimized OS Overview => Limitations:
Container-Optimized OS has limited or no support for some of the common features you may be familiar with on other operating systems:
Container-Optimized OS does not include a package manager; as such, you'll be unable to install software packages directly on an instance.
Container-Optimized OS does not support execution of non-containerized applications.
The Container-Optimized OS kernel is locked down; you'll be unable to install third-party kernel modules or drivers.
Container-Optimized OS > OS Security > Immutable root filesystem and verified boot:
The Container-Optimized OS root filesystem is always mounted as read-only. Additionally, its checksum is computed at build time and verified by the kernel on each boot. Additionally, several other mounts are non-executable by default. See Filesystem for details.
Additional information: Container-Optimized OS Overview

Using GNURadio in Python

I am trying to use GNURadio on Python 3.7. I am running on Windows 10 and using Anaconda.
Every time I try to import GNURadio, I get the following
import gnuradio
Traceback (most recent call last):
File "<ipython-input-3-9dfe3f3e2626>", line 1, in <module>
import gnuradio
ModuleNotFoundError: No module named 'gnuradio'
How can I import GNURadio in Python?
GNU Radio 3.7 is not compatible with Python3; end of story. Also, it's GNU Radio's "legacy/maintenance support release series"; don't use if for anything new! (update:) As of spring 2022, GNU Radio 3.7 is end-of-life and should not be used in anything but legacy systems.
GNU Radio 3.8 is compatible with both Py3 and Py2, but the popular GCN development GNU Radio Windows installer is built against Py2, so no, won't work for you either. 3.10 is available, and will be around for quite a while to enjoy. It is easily installable using your current Linux distro's package manager, or anaconda (on Linux, Mac OS X and Windows).
Installation instructions can be found in the GNU Radio wiki.

Python 3 virtual environment is executing python 2

This issue has had me scratching my head for a while now.
I've encountered this problem twice now, on windows 7 and windows 10. As its a closed network I've no security concerns with W7.
I have an existing Python 2.7 install - densely populated, with some fairly old library versions.
Whilst I would like to create a virtual environment for Python 2.7 I'm reluctant to do so because wheels are not available for many of the library versions I need to use, and revision histories do not appear to be available for some of these older libraries either, so without trying them I can't tell if the later library versions are backwards compatible or not. As the Python 2.7 code is from a production environment I can't break/replace it.
The python 2.7 libraries are all installed from executable installers as many of them predate
the introduction of the python wheel standard. Some also require to be built with older versions of MSVC, which is another reason for not wanting to attempt to rebuild.
It will be much easier to leave the python 2.7 install as is and start running Python 3 in virtual environments, although my original plan was to create a separate 2.7 virtual environment.
Example Python 3 virtual environment created as "py37".
In my virtual environment.
include-system-site-packages = false
When I activate the virtual environment all appears to be good.
Python -V returns 3.7.3, which is what I expect
I modified my script to output the python version (so I can track what is happening)
(py37) C:\my_folder\my_script.py
3.7.3 (v3.7.3:ef4c6ed12, Mar 25, 2019, 21:26:53) [MSC v.1916 32 bit (Intel)]
Traceback (most recent call last):
file "my_script.py", line 24, in (module)
from tk import ttk
ModuleNotFoundError: No module named 'tk'. 'tk' (python 3 lib) is not being found.
I then created two simple scripts, one using the python 2 print format, the other python 3.
Even though the virtual environment says python 3, and the python version says 3.7.3 the python 3 script fails to run.
The python 2 version of print prints out correctly, so clearly even though all indications are that Python 3 is running, it's actually Python 2.
PythonPath is null/not defined on the PC and my path variable points to my python 3 virtual environment, not my Python 2 install.
All the searching and examples I have come up with stop when version() or Python -V returns 3.x, so if it is a duplicate issue I've not managed to find the original request.
The solution to this was simple, but unpleasant.
In order for everything to work as it should I needed to explicitly identify the executable I wanted to run, every time I wanted to run it i.e. full path to the python executable in my python3 virtual environment.
I ended up creating a batch file wrapper to facilitate this
e.g. c:\apps\my_venv3\scripts\python.exe %*
Clunky, but it works, reliably, and does not break any of the existing environments.

install wxpython for python2 and 3 on ubuntu

I am running Ubuntu 16 and have both python 2 and 3. I have downloaded wxpython and it works with the python2 interpreter but not 3. I get
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>>
and
Python 3.5.2 (default, Sep 14 2017, 22:51:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'wx'
What do I need to do to get installed for python 3?
A similar situation arises on Fedora 25, on which I was able to solve this. Your mileage may vary on Ubuntu.
First note that wxPython is available in two major versions, let's call them wx3 and wx4. You can identify your running version through import wx; print(wx.version()). The version string on Fedora 25 reads '3.0.2.0 gtk3 (classic)', i.e. a brand of wx3. On sourceforge these versions are known as 'wxPython' and 'wxPython4', and wxpython.org calls wx4 'phoenix'.
Inspecting the source code of wx3 you will note that wx3's syntax is incompatible with python3. Conversely, wx4 is compatible both with python2.7 and python3.
wx4 doesn't seem to be available on Fedora 25, therefore python3 can't run any wx out-of-the-box. Ubuntu may or may not have the same issue.
The following worked for me to install wx4 in a python3 virtual environment:
pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/fedora-26 wxPython
I presume the answer to your question would be
pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 wxPython
In case you need to port a (py2, wx3) application to python3, you would be wise creating an intermediate step: (py2, wx3) -> (py2, wx4) -> (py3, wx4), noting that (py3, wx3) is an impossibility.
To create the (py2, wx4) environment was more cumbersome for me, because the above pip install command fails to find header files when run using pip2.
What ended up working for me was to download the 4.0.0b2 source https://pypi.python.org/packages/bc/6f/f7bb525517557e1c596bf22ef3f242b87afaeab57c9ad460cb94b3b0714e/wxPython-4.0.0b2.tar.gz#md5=2e3716205da8f52d8039095d14534bf7
and follow the build instructions https://github.com/wxWidgets/Phoenix/blob/master/README.rst , from which I only used the build command python build.py dox etg --nodoc sip build .
After building, you need to tell your python2 where to find the wx4 library. I ended up doing that by creating a virtualenv, and creating a symbolic link like so:
/home/user/venv/lib/python2.7/site-packages/wx -> /home/user/downloads/wxPython/wxPython-4.0.0b2/wx
That latter directory cointaining the result of the build.

Python 3.4 pip install wheel fails on Yosemite - "not a supported wheel on this platform"

I've been trying to install numpy, pysci etc on a MacBook Pro with Yosemite and fresh installation of ActiveState Python 3.4. I have tried many wheel files and they all fail with "not a supported wheel on this platform". For example, using the latest wheel file for Python 3.4 from https://pypi.python.org/pypi/numpy:
...$ sudo pip3 install numpy-1.9.1-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
numpy-1.9.1-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl is not a supported wheel on this platform.
I traced my way through wheel.py, req.py and pep425tags.py to try to understand why it failed.
In pep425tags.py it uses
distutils.util.get_platform().replace('.', '_').replace('-', '_')
which, presumably, is then compared to tags in the filename of the wheel file.
Since I have upgraded to Yosemite, I was expecting that my computer would return something like: "macosx_10_10_intel" or "macosx_10_10_x86_64" - but instead it returns "macosx_10_6_x86_64"
>>> import distutils.util
>>> distutils.util.get_platform().replace('.', '_').replace('-', '_')
'macosx_10_6_x86_64'
>>>
Am I correct that Yosemite is apparently reporting that it is Snow Leopard? Or is Python 3.4 getting it wrong? Is this my problem with wheel files? If so, is there a fix?
Updating to Python 3.4.2 corrected the problem and I was able to install the numpy wheel file.
Please note however, that distutils.util.get_platform() still reports "macosx_10_6_intel" but that does not affect the installation.
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 5 2014, 20:42:22)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> import distutils.util
>>> distutils.util.get_platform().replace('.', '_').replace('-', '_')
'macosx_10_6_intel'
Take into account that distutils.util.get_platform() returns the minimal version on which the binary will run:
For Mac OS X systems the OS version reflects the minimal version on which
binaries will run (that is, the value of MACOSX_DEPLOYMENT_TARGET
during the build of Python), not the OS version of the current system.
Emphasis mine. That said, for Python 3.4 you can reasonably expect the value to be 10.10 if you built Python on that platform.
For Python to handle MACOSX_DEPLOYMENT_TARGET to work correctly throughout, you need to upgrade to Python 3.4.2; 3.4.1 is not ready for Mac OS X 10.10 or higher. See issue #21811:
There are a number of places within the cpython code base where decisions are made based on either the running system version or the OS X ABI (e.g. the value of MACOSX_DEPLOYMENT_TARGET) that the interpreter was built with or is being built with. Most of the current tests do string comparisons of these values which will not work properly with a two-digit version number ('10.10' < '10.9' --> True).
3.4.2 includes the required fixes. The same applies to Python 2.7 up to version 2.7.7; if you see this same problem in Python 2.7 upgrade to 2.7.8 or up.
Without the fixes, intel is mixed up with x86_64, as is the case with your setup:
When running current 3.4.1 and 2.7.7 binary installers on 10.10, building C extension modules will likely result in an incorrect universal platform name, for example, "x86_64" instead of "intel", and that could affect extension module file names and wheel or egg names.
For reference, on my OS X 10.10 system, on Python 3.4.2 the result of get_platform() is:
>>> import distutils.util
>>> distutils.util.get_platform()
'macosx-10.10-x86_64'
and for Python 2.7.8 I get:
>>> import distutils.util
>>> distutils.util.get_platform()
'macosx-10.4-x86_64'

Resources