I am trying to do 'import kdb' from within a python skript.
I followed this guide for building,
https://www.libelektra.org/docgettingstarted/compiling
and I've included all plugins.
The installation I've done as described in the doc for installation for OS Independent.
I have a ubuntu 18.04.3, kdb 0.9.0 and python 3.6.8.
Do I have to install something additionally to get this working?
Thank you for reporting this problem! Seems like we are lacking documentation somewhere and/or the usability of our cmake variables is not good.
Maybe you need to set PYTHONPATH for where you installed Elektra? You need something like /usr/local/lib/python3/dist-packages (if you did not modify CMAKE_INSTALL_PREFIX).
Or the cmake call was wrong? You need something like -DSWIG_EXECUTABLE=/usr/bin/swig3.0 -DBINDINGS="cpp;swig_python".
I tried to reproduce it with docker, first I patched the Dockerfile to have sudo:
diff --git a/scripts/docker/ubuntu/bionic/Dockerfile b/scripts/docker/ubuntu/bionic/Dockerfile
index d7bd1b3e4..7d9cbf378 100644
--- a/scripts/docker/ubuntu/bionic/Dockerfile
+++ b/scripts/docker/ubuntu/bionic/Dockerfile
@@ -73,8 +73,13 @@ RUN useradd \
--shell "/bin/bash" \
jenkins
+RUN apt-get -y install sudo
+
+RUN echo "jenkins:jenkins" | chpasswd && adduser jenkins sudo
+
USER ${JENKINS_USERID}
# Set git config
RUN git config --global user.email 'Jenkins <[email protected]>' \
&& git config --global user.name 'Jenkins'
then I executed:
docker build -t buildelektra-ubuntu \
--build-arg JENKINS_USERID=`id -u` \
--build-arg JENKINS_GROUPID=`id -g` \
-f scripts/docker/ubuntu/bionic/Dockerfile \
scripts/docker/ubuntu/bionic
docker run -it --rm \
-v "$PWD:/home/jenkins/workspace" \
-w /home/jenkins/workspace \
buildelektra-ubuntu
mkdir build
cd build
cmake -DSWIG_EXECUTABLE=/usr/bin/swig3.0 -DBINDINGS="cpp;swig_python" ../workspace # ../workspace contains Elektra's source
make -j 5
sudo make install -j 5
PYTHONPATH=/usr/local/lib/python3/dist-packages python3
(where import kdb worked for me)
I also created #3186 to improve the usability for the problem you had. (I am not completely sure what went wrong, please write here how you could fix the problem, or also write if the problem persists.)
Setting the pythonpath solved the issue for me. Thank you!
Which PYTHONPATH worked for you? This should be added to the docu of the binding (in src/bindings/swig/python/README.md)
I used the one you had in your answer.
PYTHONPATH=/usr/local/lib/python3/dist-packages python3
/usr/local/... usually isn't part of pythons default search path. See python3 -c 'import sys; print(sys.path)'.
So either make sure to compile with CMAKE_INSTALL_PREFIX=/usr or tell cmake your correct python site package with e.g. PYTHON_SITE_PACKAGES=/usr/lib64/python3.y/site-packages
Ofc. you can always extend pythons default search path at runtime.