Can CPython be compiled with Clang? - python

I'm trying to build CPython using Clang, with very specific requirements:
Python 2.7.14
CentOS 6.9 (but settling for Ubuntu 16.04), x64
LLVM 5.0.0
I tried setting env variable CC to my clang executable location (i.e. /opt/llvm/5/bin/clang, but the ./configure command fails with the following:
configure: error: C compiler cannot create executables
What flags should I set to make this build work?

As the commenters on OP's post pointed out, you can compile cpython with clang. Here are reproducible instructions, in the form of a Dockerfile.
FROM ubuntu:16.04
WORKDIR /opt/cpython-2.7.14
RUN apt-get update -qq \
&& apt-get install --yes build-essential curl \
# Install clang
&& curl -fsSL https://releases.llvm.org/5.0.0/clang+llvm-5.0.0-linux-x86_64-ubuntu16.04.tar.xz \
| tar xJ -C /usr/local --strip-components 1 \
&& curl -fsSL https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz \
| tar xz --strip-components 1 \
&& CC=/usr/local/bin/clang ./configure --prefix /usr/local/cpython-2.7.14 \
&& make \
&& make install
ENTRYPOINT ["/usr/local/cpython-2.7.14/bin/python"]
docker build --tag cpython:2.7 .
docker run --rm cpython:2.7 --version
# Python 2.7.14
It is difficult to say what OP's original issue was, because it seemed like a problem with the clang installation. Looking at the configure logs would provide more information.
Disclaimer: Python 2 has reached its end of life, and ubuntu 16.04 reaches its end of life in April 2021.

tried setting env variable CC to my clang executable location
On Linux, define an alias in Bash as follows:
alias cc="clang"
On my system I set it as alias cc="clang-11"
Also, be sure to have installed all clang and llvm packages on the system.

Related

ipython version mismatches python version in docker

I'm building a docker with the following Dockerfile:
FROM ubuntu:18.04
RUN \
apt-get update -y && \
apt-get install python3.8 -y && \ <----- I ask for python3.8
apt-get install python3-pip -y && \
pip3 install ipython
When I ran the image I was surprised to see that the version of ipython is 3.6.9:
$ docker build --tag versions --file .\Dockerfile.txt .
$ docker run -d -t --name ver versions
ba9bd772bc6d247a6c83f2bf932a6c5172c23f00e1e6a35f14878608d0f35f89
$ docker exec -it ver bash
# ipython
Python 3.6.9 (default, Jan 26 2021, 15:33:00)
The package python3-pip depends on python3, and the default python3 for ubuntu 18.04 is version 3.6.
There are at least three options.
Use a python base image
The official python base images include pip. If possible, I would use one of these.
python:3.8 - includes compilers to install compiled packages
python:3.8-slim - does not include compilers
Install pip with the get-pip.py script
One can install pip without the system package manager, for example with the script get-pip.py:
wget https://bootstrap.pypa.io/get-pip.py
python3.8 get-pip.py
Use ubuntu 20.04
As #NickODell comments, ubuntu 20.04 uses 3.8 as the default python. But you will have less fine-grained control over the python version than if you use one of the official python docker images.

Loading openvino python library on Raspebrry pi 4

After followign the guides (and coming through the github trackers), I was able to get OpenVINO to install on my pi4 and can run /opt/intel/openvino/bin/armv7l/Release/object_detection_sample_ssd successfully using my own trained model.
I used the follow cmake command most recently, but I've done pretty much all iterations I could find on the several instruction pages.
cmake -DCMAKE_BUILD_TYPE=Release /
-DENABLE_SSE42=OFF /
-DTHREADING=SEQ /
-DENABLE_GNA=OFF /
-DENABLE_PYTHON=ON /
-DPYTHON_EXECUTABLE=/usr/bin/python3 /
-DPYTHON_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpython3.7m.so /
-DPYTHON_INCLUDE_DIR=/usr/include/python3.7m /
-NGRAPH_PYTHON_BUILD_ENABLE=ON /
-DCMAKE_CXX_FLAGS=-latomic /
-DOPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic /
-D CMAKE_INSTALL_PREFIX=/usr/local /
.. && make
When I try one of the python examples I get
ModuleNotFoundError: No module named 'ngraph'
Looking more into it now and it appears the issue is the "setupvars.sh" script not calling into the right directory. I was able to get the module openvino to load by adjusting the export path. I must say the amount of documentation that is, quite frankly all over the place and seems to have wrong directory structures left and right.
As of right now, the builds for the Raspberry Pi are not being made with NGRAPH compiled. The user has to compile it themselves from scratch per this thread. https://community.intel.com/t5/Intel-Distribution-of-OpenVINO/No-ngraph-bindings-for-python-in-raspbian-distribution/m-p/1263401#M23093
The comment by the Intel "Support" is wrong and won't work on new builds.
Please refer to the steps below for building Open Source OpenVINO™ Toolkit for Raspbian OS:
Set up build environment and install build tools
sudo apt update && sudo apt upgrade -y
sudo apt install build-essential
Install CMake from source
cd ~/
wget https://github.com/Kitware/CMake/releases/download/v3.14.4/cmake-3.14.4.tar.gz
tar xvzf cmake-3.14.4.tar.gz
cd ~/cmake-3.14.4
./bootstrap
make -j4 && sudo make install
Install OpenCV from source
sudo apt install git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python3-scipy libatlas-base-dev
cd ~/
git clone --depth 1 --branch 4.5.2 https://github.com/opencv/opencv.git
cd opencv && mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
make -j4 && sudo make install
Download source code and install dependencies
cd ~/
git clone --depth 1 --branch 2021.3 https://github.com/openvinotoolkit/openvino.git
cd ~/openvino
git submodule update --init --recursive
sh ./install_build_dependencies.sh
cd ~/openvino/inference-engine/ie_bridges/python/
pip3 install -r requirements.txt
Start CMake build
export OpenCV_DIR=/usr/local/lib/cmake/opencv4
cd ~/openvino
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/home/pi/openvino_dist \
-DENABLE_MKL_DNN=OFF \
-DENABLE_CLDNN=OFF \
-DENABLE_GNA=OFF \
-DENABLE_SSE42=OFF \
-DTHREADING=SEQ \
-DENABLE_OPENCV=OFF \
-DNGRAPH_PYTHON_BUILD_ENABLE=ON \
-DNGRAPH_ONNX_IMPORT_ENABLE=ON \
-DENABLE_PYTHON=ON \
-DPYTHON_EXECUTABLE=$(which python3.7) \
-DPYTHON_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpython3.7m.so \
-DPYTHON_INCLUDE_DIR=/usr/include/python3.7 \
-DCMAKE_CXX_FLAGS=-latomic ..
make -j4 && sudo make install
Configure the Intel® Neural Compute Stick 2 Linux USB Driver
sudo usermod -a -G users "$(whoami)"
source /home/pi/openvino_dist/bin/setupvars.sh
sh /home/pi/openvino_dist/install_dependencies/install_NCS_udev_rules.sh
Verify nGraph module binding to Python
cd /home/pi/openvino_dist/deployment_tools/inference_engine/samples/python/object_detection_sample_ssd
python3 object_detection_sample_ssd.py -h

How to: Upgrade to Python 3.8.5 on ArchLinux / Raspbian / Volumio / Raspberry

I've faced the Problem, that my code needs at least Python 3.5... therfore I upgraded to Python 3.5.2.
Unfortunatly the support for Python 3.5.x ehas ended and the support for PIP 21.0 will end in a few month...
So I needed to upgrade aggain.
You can find the whole Code behind it here.
As soon I started to attemped the Upgrade/Upodate I noticed:
There are no Guides in the Web to install Python 3.8.5 on a Raspberry/ArchLinux/Raspbian
If you do the usual stepps you mess up SSL -> No Webinterface, No SSH, No GIT, No Pip Install...
So here you are, if you follow the steps, you should have a running Python 3.8.5 (Alt-)Installation.
Please Notice: In my Installation Steps I used the standard folder /home/USER/ -> Please change this to your Username! (For Volumio this would be: /home/volumio)
sudo apt-get update
sudo apt-get install -y build-essential libffi-dev libc6-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev
cd
mkdir /home/USER/src
cd /home/USER/src && mkdir openssl && cd openssl
wget https://www.openssl.org/source/openssl-1.1.1b.tar.gz
tar xvf openssl-1.1.1b.tar.gz && cd openssl-1.1.1b
./config --prefix=/home/USER/src/openssl-1.1.1b --openssldir=/home/USER/src/openssl-1.1.1b && make && sudo make install
cd
echo "/home/USER/src/openssl-1.1.1b/lib" >> /etc/ld.so.conf.d
sudo ldconfig
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/USER/src/openssl-1.1.1b/lib
cd /home/USER/src && mkdir python && cd python
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
tar xf Python-3.8.5.tar.xz
cd Python-3.8.5
sudo nano /home/USER/src/python/Python-3.8.5/Modules/Setup
Here please UN-comment lines 210-213, and change line 210 to:
SSL=/home/USER/src/openssl-1.1.1b
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
Save and exit with: ctrl+x, y, enter
./configure --prefix=/home/USER/src/Python-3.8.5 --with-openssl=/home/USER/src/openssl-1.1.1b && make -j4 && sudo make altinstall
export PATH=~/home/USER/src/Python-3.8.5/bin:$PATH
export LD_LIBRARY_PATh=/home/USER/src/Python-3.8.5/bin
sudo /home/USER/src/Python-3.8.5/bin/pip3.8 install -U pip #
sudo /home/USER/src/Python-3.8.5/bin/pip3.8 install -U setuptools #
sudo /home/USER/src/Python-3.8.5/bin/pip3.8 install --upgrade setuptools pip wheel #
Now you are ready to go!
To use PIP3(.8) type:
sudo /home/USER/src/Python-3.8.5/bin/pip3.8 YOURCOMMAND --YOUROPTIONS
To use Python3(.8) type:
sudo /home/USER/src/Python-3.8.5/bin/python3.8 YOURCOMMAND --YOUROPTIONS
The Idea behind it: We Install OpenSSL 1.1.1b (needed by Python 3.8.5) to an alternative directory, so that the standard OpenSSL is still functional. After that, we Alt-Install Python 3.8.5 and tell it in the installation Process to use our custom OpenSSL Installation.
My Solution may not be the best, but it is functional.
If you have ideas how to make it better / simpler, please make a comment.
Cheers!

Building Python 3.6.4 on Linux from scratch

I'm trying to build Python 3.6.4 from LFS 8.2-systemd so I run the configure command:
./configure --prefix=/usr \
--enable-shared \
--with-system-expat \
--with-system-ffi \
--with-ensurepip=yes
followed by make -j.
However, at this point the module "pyexpat" is not found by Python, but the file exists in /usr/lib/libexpat.so.
After reading building Python from source with zlib support, I created a symlink:
ln -s /usr/lib /usr/lib/x86_64-gnu-linux
If i run make install, I get an error:
ModuleNotFoundError: No module named pyexpat
My expat lib version is 2.2.5.
I'm doing the compilation inside env -i chroot /mnt bash
and my environment just contains a valid PATH and LX_ALL=POSIX variables.
I ran into this same problem for python 3.6.8 , when I initially configured using:
./configure --prefix=/opt/python-3.6/ --enable-optimizations
However, when I retried using the command in the BLFS book:
./configure --prefix=/opt/python-3.6/ --enable-shared --with-system-expat --with-system-ffi --with-ensurepip=yes
My pyexpat started working.
That being said, I think it may be helpful to just retry, since my second command is functionally identical to yours.
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6
To make python3 use the new installed python 3.6 instead of the default 3.5 release, run following 2 commands:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
Finally switch between the two python versions for python3 via command:
sudo update-alternatives --config python3
After selecting version 3.6:
python3 -V

python 3.6 installation and lib64

I'm trying to install the new Python (3.6, released just a few weeks back) from source on openSUSE 42.2. Everything
./configure --prefix /home/paul/2017 --enable-optimizations
make
make install
appears to work just fine, but when I call the shiny new interpreter I get this error:
Python 3.6.0 (default, Jan 9 2017, 22:01:27)
[GCC 4.8.5] on linux
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "/home/paul/.pythonrc", line 7, in <module>
import readline
ModuleNotFoundError: No module named 'readline'
Now, the module is there, it is installed under $PREFIX/lib64/python3.6/lib-dynload/readline.cpython-36m-x86_64-linux-gnu.so.
Only the interpreter is not looking there (it is completely ignoring lib64, I checked with -vv).
Update: To be clear, this does not only affect readline but everything under lib64, most notably the modules under lib-dynload.
This appears to be a known issue, see the Python bugtracker. It's a fairly lengthy exchange ending in
Is there agreement on what needs doing here? I'd like to see this into 3.5 before it reaches its 10th birthday :)
This leaves me a bit confused. Is this supposed to be resolved?
I do not remember ever running into this issue before, so I wonder if it is a 3.6 regression.
And obviously, any fix would be most welcome.
Update: for the time being I can work around the issue by symlinking everything under lib64 into lib. Obviously, that is not an ideal solution; at the very least it defeats the purpose of introducing lib64 (being able to have 32 and 64 bit versions side-by-side) in the first place.
I'd much prefer something in a config file.
The opensuse openSUSE:Factory python3x has patches for that.
Links:
Python 3.6 Python 3.8 Python 3.9
Spec files are usually a good starting point.
Note: the install step would install a python3 in /usr/local/bin. Changing that to altinstall avoids shadowing the system-wide python3.
Install
Create a downloads variable pointing to a directory where all downloaded files (python source and factory patches) will be saved
export downloads=/usr/local/build/downloads
In a user writable directory:
tar --no-same-owner -xvf $downloads/Python-3.6.4.tar.xz
cd Python-3.6.4
patch -p1 < $downloads/python-3.6.0-multilib-new.patch
patch -p0 < $downloads/python-3.3.0b1-localpath.patch
patch -p0 < $downloads/python-3.3.0b1-curses-panel.patch
# mind this step, otherwise
# none of the modules in `lib-dynload` could be imported !
autoreconf -i
mkdir build; cd $_
../configure --enable-optimizations --enable-ipv6 \
--with-fpectl --enable-shared --with-system-ffi \
--with-system-expat --enable-loadable-sqlite-extensions
make -j $(nproc)
# altinstall, not install (see above)
sudo make altinstall
Uninstall
To get rid of the installed files:
sudo rm -rf /usr/local/lib64/python3.6/
sudo rm -f /usr/local/lib64/libpython3.6m*
sudo rm -f /usr/local/lib64/libpython3.so
sudo rm -f /usr/local/lib64/pkgconfig/python-3.6*
sudo rm -f /usr/local/bin/python-3.6*
For python3.7
tar --no-same-owner -xvf $downloads/Python-3.7.3.tar.xz
cd Python-3.7.3
patch -p1 < $downloads/python-3.7.3-python-3.6.0-multilib.patch
patch -p1 < $downloads/python-3.7.3-distutils-reproducible-compile.patch
patch -p0 < $downloads/python-3.7.3-python-3.3.0b1-localpath.patch
patch -p0 < $downloads/python-3.7.3-00251-change-user-install-location.patch
# do not forget !
autoreconf -i
mkdir build; cd $_
../configure --enable-optimizations --enable-ipv6 --enable-shared --with-system-ffi --with-system-expat --enable-loadable-sqlite-extensions
make -j $(nproc)
sudo make altinstall
For python 3.8
tar --no-same-owner -xvf $downloads/Python-3.8.1.tar.xz
cd Python-3.8.1/
patch -p1 < $downloads/python-3.8.1-F00102-lib64.patch
patch -p1 < $downloads/python-3.8.1-F00251-change-user-install-location.patch
patch -p1 < $downloads/python-3.8.1-SUSE-FEDORA-multilib.patch
patch -p1 < $downloads/python-3.8.1-distutils-reproducible-compile.patch
patch -p1 < $downloads/python-3.8.1-python-3.3.0b1-localpath.patch
# do not forget !
autoreconf -i
mkdir build; cd $_
../configure --enable-optimizations --enable-ipv6 --enable-shared \
--with-system-ffi --with-system-expat \
--enable-loadable-sqlite-extensions
make -j $(nproc)
# altinstall, not install (see above)
sudo make altinstall
Ok, I found a solution: If one configures with the --enable_shared option the problem somehow goes away. Good enough for me.

Categories

Resources