How do I install `python39-rpm-macros` for Fedora 35? - python

How do I select the Python version when building a RPM from a .spec file on Fedora 35?
The CentOS/RHEL documentation says
Configure the particular Python 3 version in the BuildRequires of the SPEC file to python36-rpm-macros, python38-rpm-macros, or python39-rpm-macros.
CHAPTER 40. PACKAGING PYTHON 3 RPMS
Fedora only has a python3.9 package and python3-rpm-macros package.
How can I set the Python version? How can I make this selection portable between Fedora, RHEL, and other Enterprise Linux flavors?
Attempt at solution
%define __python3 /usr/bin/python3.9
%{?fedora:BuildRequires: python3.9}
%{?rhel:BuildRequires: python39-devel}
Is this correct?

%global python_minimum_version 3.9.0
%{?fedora:Requires: python3 >= %{python_minimum_version}}
%{?rhel:Requires: python39 >= %{python_minimum_version}}
%{?fedora:BuildRequires: python3-devel >= %{python_minimum_version}}
# yes, I do crazy things in the rpm build, and I need pip
%{?fedora:BuildRequires: python3-pip}
# without wheel the installed files lack `python_qpid_proton-0.37.0.dist-info`
%{?fedora:BuildRequires: python3-wheel}
%{?rhel:BuildRequires: python39-devel >= %{python_minimum_version}}
%{?rhel:BuildRequires: python39-pip}
%{?rhel:BuildRequires: python39-wheel}
%{?rhel:BuildRequires: python39-rpm-macros}
This seems to produce a package that behaves well on both Fedora and CentOS Stream 8.
On Fedora, latest Python is used, and on CentOS I get Python 3.9 and the #! lines in script get rewritten to use that Python 3.9 automatically.
I consider this a success.

Related

pyenv building python on Linux Mint with WARNING: renaming "_ctypes"

For some reason, pyenv is failing to install any versions of python due to an issue with libffi. I have all the libraries installed, yet I get:
*** WARNING: renaming "_ctypes" since importing it failed: libffi.so.8: cannot open shared object file: No such file or directory
The curious thing is libffi is installed, but it's a different version:
❯ find /usr -name '*ffi.so*'
/usr/lib/x86_64-linux-gnu/libffi.so
/usr/lib/x86_64-linux-gnu/libffi.so.7
/usr/lib/x86_64-linux-gnu/libffi.so.7.1.0
So, the build is trying libffi.so.8 even though libffi.so.7 is installed.
Can anybody explain how debian-based systems choose the version of the shared library? I've checked the .h and .pc files, but nothing jumps out at me showing why it would be referencing version 8.
❯ ldconfig -p | grep libffi.so
libffi.so.7 (libc6,x86-64) => /lib/x86_64-linux-gnu/libffi.so.7
libffi.so.7 (libc6) => /lib/i386-linux-gnu/libffi.so.7
libffi.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libffi.so
Additional note: I notice libffi is also installed by homebrew. However, it's the same version as Mint has installed, so it's not a conflict (as far as I can tell).
Any suggestions?
❯ uname -a
Linux mcrowe-XPS-15-9560 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
❯ cat /etc/lsb-release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=20.2
DISTRIB_CODENAME=uma
DISTRIB_DESCRIPTION="Linux Mint 20.2 Uma"
FWIW, I am seeing a similar issue. When I installed 3.9.7 with pyenv, it found libffi correctly. Today, when I install 3.9.9 I get the same error as you.
*** WARNING: renaming "_ctypes" since importing it failed: libffi.so.8: cannot open shared object file: No such file or directory
The symptom that got me looking into this was an attempt to pip install blinker which gave me an error about missing _ctypes, which was odd since 3.9.7 had no issues.
ModuleNotFoundError: No module named '_ctypes'
In my case brew had updated to libffi 3.4 vs the 3.3 that Ubuntu 20.04 is using. I figure there must be some misordering of paths where it finds the brew headers to compile, but cannot find the brew .so to link.
I would like to learn to sort that out, but in the meantime, I did the following, answering y to the pyenv prompt to reinstall over existing 3.9.9
$ brew remove --ignore-dependencies libffi
$ pyenv install 3.9.9
$ brew install libffi
That was enough of a workaround to let me return to what I wanted to deal with.

How to install Python 3.8 on Alpine Linux not from Python base image

Specifically in this base image https://hub.docker.com/r/frolvlad/alpine-glibc/ how does one add Python 3.8 to it.. Adding python3 installs Python3.6.9. Went through How do I install python on alpine linux? but couldn't figure it out.
Another solution, use official Python Docker image and COPY:
FROM python:3.8.13-alpine3.16 as python
COPY --from=python /usr/local/bin/python3 /usr/local/bin/python3
COPY --from=python /usr/local/lib/python3.8 /usr/local/lib/python3.8
COPY --from=python /usr/local/lib/libpython3.8.so.1.0 /usr/local/lib/libpython3.8.so.1.0
COPY --from=python /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so
In the time of writing, the latest frolvlad/alpine-glibc image is based on Alpine 3.13.2. The current Python 3 version for Alpine 3.13 is 3.8.8. Therefore, for installing Python 3.8 simply install the python3 package. This is also true for Alpine 3.12 and 3.11.
If you're using frolvlad/alpine-glibc based on Alpine 3.13, 3.12 or 3.11, try updating the apk database with apk update followed by apk add python3.
On images based on older Alpine versions, such as Alpine 3.9, you'll not be able to install a functional Python 3.8, since it depends on musl 1.1.24 which is only available starting Alpine 3.10. Even though it could be installed using the Alpine 3.11+ repositories, it will fail to run due to the said musl dependency:
/ # apk add python3=3.8.2-r2 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.11/main
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
(1/10) Installing libbz2 (1.0.8-r1)
(2/10) Installing expat (2.2.9-r1)
(3/10) Installing libffi (3.2.1-r6)
(4/10) Installing gdbm (1.13-r1)
(5/10) Installing xz-libs (5.2.4-r0)
(6/10) Installing ncurses-terminfo-base (6.1_p20200118-r4)
(7/10) Installing ncurses-libs (6.1_p20200118-r4)
(8/10) Installing readline (8.0.1-r0)
(9/10) Installing sqlite-libs (3.30.1-r2)
(10/10) Installing python3 (3.8.2-r2)
Executing busybox-1.29.3-r10.trigger
Executing glibc-bin-2.29-r0.trigger
OK: 71 MiB in 27 packages
/ # python3 --version
Error relocating /usr/lib/libpython3.8.so.1.0: copy_file_range: symbol not found

Installing hyperledger indy node code fails on python3 not being default on Mac

I am installing Hyperledger Indy (sovrin) self-identity software per these instructions.
I have Python2.7 installed via Anaconda 3. I also have Python3.6.3 installed that I downloaded and installed from here.
I'm trying to install some other software that has a dependency for Python > 3.5.
I've tried several methods to change my default Python:
Per this SO I set it manual in current terminal window:
alias python='python3'
Per same SO I vi .bash_profile and added:
alias python='python3'
then source ~/.bash_profile
Set a link to Python3:
bc-computer:~ momi$ unlink /usr/local/bin/python2
bc-computer:~ momi$ ln -s /usr/local/bin/python3 /usr/local/bin/python
but still continue to get the same error:
bc-computer:~ momi$ pip install indy-node-dev
Collecting indy-node-dev
Using cached indy-node-dev-1.2.227.tar.gz
Complete output from command python setup.py egg_info:
FAIL: Requires Python 3.5 or later, but setup.py was run using 2.7.14
NOTE: Installation failed. Run setup.py using python3
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3f/sh6dr8wx6w720b1_w38f_fh00000gq/T/pip-build-ecZnYY/indy-node-dev/
I also tried setting up a python3 test environment per this:
python3 setup.py test
And got this error:
> /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python:
> can't open file 'setup.py': [Errno 2] No such file or directory
Please note that I tried this suggestion which seems to be the non-duplicate answer but didn't work for me:
The safest way is to set an alias in ~/.bashrc:
alias python=python3
My environment:
uname -msra
Darwin bc-computer.local 17.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64
My OS:
High Sierra 10.13.1
which -a python
/Users/momi/anaconda2/bin/python
/usr/local/bin/python
/usr/bin/python
Thank you
Ok the solution was to use pip3 rather than pip for my install command per Mike Mueller's answer here:
pip3 install indy-node-dev
I assume that pip3 points to python3x rather than 2x.
I have also installed Hyperledger Indy SSI VC using MacOs Python 3.6.3. It is working for for me. I could demo the VON Network. It seems that your machine environment still points to Python 2.7. There are different ways by which we can point to Python 3.6.3 through virtual environment. You can try those options.

cqlsh does not work for Cassandra 3.11X and Python 2.7.X

When i Install Cassandra 3.11X and Python 2.7.X in Debian 8.8, the Cqlsh does not start.
I get the following error.
debian#vm-184:/opt/apache-cassandra-3.10/bin$ ./cqlsh
Python Cassandra driver not installed, or not on PYTHONPATH.
You might try "pip install cassandra-driver".
Python: /usr/local/bin/python
Module load path: ['/opt/apache-cassandra-3.10/bin/../lib/six-1.7.3-py2.py3-none-any.zip', '/opt/apache-cassandra-3.10/bin/../lib/futures-2.1.6-py2.py3-none-any.zip', '/opt/apache-cassandra-3.10/bin/../lib/cassandra-driver-internal-only-3.7.0.post0-2481531.zip/cassandra-driver-3.7.0.post0-2481531', '/opt/apache-cassandra-3.10/bin', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
Error: can't decompress data; zlib not available
How do we resolve this
On RedHat 7x - Install the following packages:
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
Then...
# vi .../Python-2.7.13/Modules/Setup
uncomment the line:
...
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
AND (re-)compile python source:
# cd .../Python-2.7.13/Modules/
# ./configure
# make
# make install
Error: can't decompress data; zlib not available
Is the zlib library install?
please install zlib first.
This issue generally comes when your machine has Python 2.6 or below.
Check the answer over here cassandra 2.2 CQl Shell supports python 2.7 on how to start cqlsh using python 2.7
Quoting - "Depending on your distribution and its version you cannot change the default python version of the system without breaking the system."
I would recommend you to choose Debian version that uses Python2.7x natively.

Compile Python 3.4 with sqlite3

I have compiled SQLite3 3.8.6 and installed it to ${HOME}/opt with:
LDFLAGS="-L${HOME}/opt/lib" CFLAGS="-L${HOME}/opt/include" ./configure --prefix=$HOME/opt
make && make install
I am now trying to compile Python 3.4.2 to use this version instead of the version installed for the entire system. I do not have root access on this system. To compile Python, I am using:
LDFLAGS="-L${HOME}/opt/lib" CFLAGS="-L${HOME}/opt/include" ./configure --prefix=$HOME/opt
make && make install
I was able to compile Python 3.3.5 with my newer version if SQLite3, but these same steps don't seem to work for me for 3.4.2.
How can I compile Python 3.4.2 to include my version of SQLite 3.8.6 which is located in ${HOME}/opt?
Thanks.
EDIT: It compiles & installs OK except for the fact that is using the older, system version of sqlite3 instead of the version that I compiled & installed myself.
There is also the option of pre-linking your custom Python build with your own-built sqlite3. (I had the same issue: the custom python was using the system-provided sqlite3, completely ignoring the sqlite3 I built).
Prefix your configure and make commands with:
LD_RUN_PATH=$HOME/opt/lib configure LDFLAGS="-L$HOME/opt/lib" CPPFLAGS="-I$HOME/opt/include" …
LD_RUN_PATH=$HOME/opt/lib make
so that the built python3 by default is linked to your sqlite3.
This worked for me.
import platform,sqlite3
print("Oper Sys : %s %s" % (platform.system(), platform.release()))
print("Platform : %s %s" % (platform.python_implementation(),platform.python_version()))
print("SQLite : %s" % (sqlite3.sqlite_version))
When I run this code, the output contains the system's version of sqlite3:
Oper Sys : Linux 3.2.0-4-amd64
Platform : CPython 3.4.2
SQLite : 3.7.13
After installing sqlite v3.8.6 under ${HOME}/opt{include,lib} and setting this in my .bashrc:
export LD_LIBRARY_PATH="${HOME}/opt/lib"
I get my desired result:
Oper Sys : Linux 3.2.0-4-amd64
Platform : CPython 3.4.2
SQLite : 3.8.6
Notice the SQLite version changes from 3.7.13 to 3.8.6
Hi for me helped this:
cd /tmp
wget https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
tar xvf sqlite-autoconf-3280000.tar.gz
mv /usr/bin/sqlite3 /usr/bin/sqlite3.7
cp /tmp/sqlite-autoconf-3280000/sqlite3 /usr/bin/sqlite3
cp /tmp/sqlite-autoconf-3280000/.libs/libsqlite3.so.0.8.6 /usr/lib64/libsqlite3.so.0.8.6
cp /tmp/sqlite-autoconf-3280000/.libs/libsqlite3.so.0 /usr/lib64/libsqlite3.so.0

Categories

Resources