ImportError: No module named couchbase._libcouchbase - python

This only happens for me in Travis under the pypy build.
Here's the exact error string:
Traceback (most recent call last):
File "app_main.py", line 75, in run_toplevel
File "app_main.py", line 581, in run_it
File "<string>", line 1, in <module>
File "tests/test_pycouchbase.py", line 15, in <module>
from pycouchbase.utils import *
File "pycouchbase/__init__.py", line 8, in <module>
from .connection import Connection
File "pycouchbase/connection.py", line 3, in <module>
from couchbase.bucket import Bucket
File "/home/travis/virtualenv/pypy-2.5.0/site-packages/couchbase/__init__.py", line 28, in <module>
from couchbase.user_constants import *
File "/home/travis/virtualenv/pypy-2.5.0/site-packages/couchbase/user_constants.py", line 21, in <module>
import couchbase._bootstrap
File "/home/travis/virtualenv/pypy-2.5.0/site-packages/couchbase/_bootstrap.py", line 34, in <module>
import couchbase.exceptions as E
File "/home/travis/virtualenv/pypy-2.5.0/site-packages/couchbase/exceptions.py", line 18, in <module>
import couchbase._libcouchbase as C
ImportError: No module named couchbase._libcouchbase
I'm already trying to install couchbase_cffi, but it looks like _libcouchbase.so file is still missing.
Link to build: https://travis-ci.org/ardydedase/pycouchbase/jobs/75973023#L1782
Travis config file:
# Config file for automatic testing at travis-ci.org
language: python
python:
- "3.4"
- "3.3"
- "2.7"
- "2.6"
- "pypy"
before_install:
- sudo rm -rf /etc/apt/sources.list.d/*
- sudo add-apt-repository -y ppa:pypy/ppa
- wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -
- echo deb http://packages.couchbase.com/ubuntu precise precise/main | sudo tee /etc/apt/sources.list.d/couchbase.list
- sudo apt-get update
- sudo apt-cache search libcouchbase
install:
# GCC
- sudo apt-get install python-software-properties
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update
- sudo apt-get -y install gcc-4.8
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
# libcouchbase dependencies
- sudo apt-get -y install libxml2-dev libxslt-dev python-all-dev libffi6 libffi-dev
- sudo apt-get -y install build-essential libssl-dev python-openssl
- sudo apt-get -y install libcouchbase-dev libcouchbase2-core libcouchbase2-libevent libevent-dev python-gevent
- pip -q install gevent || echo "Couldn't find gevent"
- pip -q install twisted
- pip -q install testresources
- pip install -r requirements.txt
# command to run tests, e.g. python setup.py test
script:
# - cd couchbase-python-cffi
# - export CFLAGS=-Qunused-arguments
# - export CPPFLAGS=-Qunused-arguments
# - python setup.py test
# - python setup.py build
- echo $PWD
# - if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then git clone https://github.com/couchbase/couchbase-python-client.git && cd couchbase-python-client && python setup.py build_ext --inplace && cd ..; fi
- if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then cd couchbase-python-cffi && python setup.py build && python setup.py install && cd .. && ls -al; fi
- if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then ls -al /home/travis/virtualenv/pypy-2.5.0/site-packages/couchbase; fi
- python -c "from tests import test_pycouchbase; print(test_pycouchbase)"
- python runtests.py
I did try to refer to this thread: https://forums.couchbase.com/t/installing-couchbase-1-0-0-on-ubuntu/291, but I can't find the build folder that is being referred in there.

If using the cffi module, you must import couchbase_ffi before anything else. The reason is that couchbase_ffi injects itself as the couchbase._libcouchbase module.
Under the "normal" extension, couchbase._libcouchbase contains the normal CPython extension code which is built. Since CPyext doesn't really work under pypy, the building of the code is disabled on that platform, and you are required to "inject" the ffi module beforehand.
Admittedly it's an annoying step and not the most 'transparent'. You might be able to do something like.. (untested!!!): try import couchbase; except ImportError: import couchbase_ffi

Related

Can't install Python modules in Gitlab CI

I can't get Gst (or seemingly any Python module) to install inside Gitlab CI
Here is my .gitlab-ci.yml file
image: "python:3.7"
before_script:
- apt-get -qq update
- apt-get -qq install -y python3-dev python3-pip libgirepository1.0-dev
- python3 --version
- python3 -m pip install --upgrade pip
- pip3 install -r requirements.txt
test:
script:
- pip3 install flake8 # you can also use tox
- flake8 --max-line-length=254 --extend-ignore=F401,E402 matinee.py
run:
script:
- ./matinee.py -h
But no matter what I tried the closest I got to was:
$ ./matinee.py -h
Traceback (most recent call last):
File "./matinee.py", line 6, in <module>
gi.require_version('Gst', '1.0')
File "/usr/local/lib/python3.7/site-packages/gi/__init__.py", line 126, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gst not available
Before that it complained that gi didn't exist (?) so basically it seems like python modules are not installable this way.
It's been a week now, and frankly I'm giving up on setting up Gitlab CI for python ; I have nodejs projects with tons of deps passing installing without a glitch ; This post is my last hail Mary attempt :|
Naturally, everything works perfectly locally (Ubuntu 22)
My requirements file
# cat requirements.txt
PyGObject==3.42.1
What I tried
image: "python:3.7"
image: "python:latest"
image: "ubuntu:latest"
venv
And everything on this page. Please, help me understand why I can't install Python modules in Gitlab CI.

How to install pyside2-uic in Ubuntu 16.04?

I've tried installing Pyside2-uic using :
sudo apt-get install -y python-pyside2
sudo apt-get install pyside2-tools
while I'm converting the .ui file to .py using pyside2-uic still i get error as " ImportError: No module named pyside2uic.driver "
Traceback (most recent call last):
File "/usr/bin/pyside2-uic", line 28, in <module>
from pyside2uic.driver import Driver
ImportError: No module named pyside2uic.driver
How to resolve this error
I tried these commands and it worked.
$ apt-get install wget python-pip python-dev software-properties-common
$ add-apt-repository ppa:beineri/opt-qt561-trusty
$ apt-get update
$ apt-get install qt56-meta-full
$ . /opt/qt56/bin/qt56-env.sh
$ wget https://bintray.com/fredrikaverpil/pyside2-wheels/download_file?file_path=ubuntu14.04%2FPySide2-2.0.0.dev0-cp27-none-linux_x86_64.whl -O PySide2-2.0.0.dev0-cp27-none-linux_x86_64.whl
$ pip install PySide2-2.0.0.dev0-cp27-none-linux_x86_64.whl
$ pyside2-uic

Install GDAL/OGR Python API on Debian

I trying to install Python GDAL/OGR bindings to be accessible directly from Python interpreter on Docker python:3.6-stretch image.
My Dockerfile looks like that:
FROM python:3.6-stretch
ENV PYTHONUNBUFFERED 1
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN apt-get update && apt-get install -y \
binutils \
libproj-dev \
gdal-bin \
libgdal-dev \
python3-gdal \
python3-pip \
python-numpy \
python-dev \
vim
COPY . /app
RUN pip3 install --no-cache-dir -r /app/requirements.txt \
&& rm -rf /requirements.txt
WORKDIR /app
Dockerfile installs current stable version of GDAL and python3-gdal which is 2.1.2.
Import osgeo from Python interpreter gives me an error:
>>> from osgeo import gdal
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'osgeo'
How to install neccessary libs properly?
Check if you are using correct python 3 interpreter. You can call in linux system:
whereis python3
You had install python3-pip package, so you have osgeo in your main python 3 in /usr/bin/python3. In other python 3 locations osgeo can be not available.
I solved this problem by installing via Python PIP pygdal package. Firstly you need to check Gdal version installed on the machine, and install proper pygdal.
$ gdalinfo --version
GDAL 2.1.3, released 2017/20/01
$ pip install "pygda>=2.1.2,<2.1.3"

failing pjsua python module

I try to use pjsua module for Python on Ubuntu 16.04.
When I try to call AccountConfig, it will return with following error message:
>>> import pjsua
>>> t=pjsua.AccountConfig()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pjsua.py", line 802, in __init__
self._cvt_from_pjsua(default)
File "pjsua.py", line 859, in _cvt_from_pjsua
for cred in cfg.cred_info:
MemoryError
Compiled pjsip with following:
sudo apt-get install build-essential python-dev libpjsua2
wget http://www.pjsip.org/release/2.7.2/pjproject-2.7.2.tar.bz2
sudo rm -fr pjproject-2.7.2
tar -xf pjproject-2.7.2.tar.bz2 && cd pjproject-2.7.2/
export CFLAGS="$CFLAGS -fPIC"
./configure --enable-shared --disable-sound && make dep && make
cd pjsip-apps/src/python/
sudo python setup.py install
I would appreciate any idea, what am I doing wrong.
Compile with following solved the issue:
sudo apt-get update
sudo apt-get -y install build-essential python-dev libpjsua2 libssl-dev libasound2-dev
wget http://www.pjsip.org/release/2.7.2/pjproject-2.7.2.tar.bz2
tar -xf pjproject-2.7.2.tar.bz2 && cd pjproject-2.7.2/
export CFLAGS="$CFLAGS -fPIC"
./configure && make dep && make
cd pjsip-apps/src/python/
sudo python setup.py install

Docker: How to run cython_extensions?

FROM ubuntu:14.04.2
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -y update && apt-get upgrade -y
RUN apt-get install python build-essential python-dev python-pip python-setuptools -y
RUN apt-get install libxml2-dev libxslt1-dev python-dev -y
RUN apt-get install libpq-dev postgresql-common postgresql-client -y
RUN apt-get install openssl openssl-blacklist openssl-blacklist-extra -y
RUN apt-get install nginx -y
RUN pip install "pip>=7.0"
RUN pip install virtualenv uwsgi
ADD canonicaliser_api /home/ubuntu/canonicaliser_api
RUN virtualenv /home/ubuntu/canonicaliser_api/venv
RUN source /home/ubuntu/canonicaliser_api/venv/bin/activate && pip install -r /home/ubuntu/canonicaliser_api/requirements.txt
RUN export CFLAGS=-I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/
RUN source /home/ubuntu/canonicaliser_api/venv/bin/activate && \
python /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/setup.py \
build_ext --inplace
The last line crashes with:
Traceback (most recent call last):
File "/home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/setup.py", line 5, in <module>
ext_modules = cythonize("*.pyx")
File "/home/ubuntu/canonicaliser_api/venv/local/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 754, in cythonize
aliases=aliases)
File "/home/ubuntu/canonicaliser_api/venv/local/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 649, in create_extension_list
for file in nonempty(extended_iglob(filepattern), "'%s' doesn't match any files" % filepattern):
File "/home/ubuntu/canonicaliser_api/venv/local/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 103, in nonempty
raise ValueError(error_msg)
ValueError: '*.pyx' doesn't match any files
...
What am I missing please?
I found the problem.
I had to downgrade to Cython 0.21 (This is main reason for the
error in question)
Afterwards I got another problem as the script didn't generate
anything, despite not throwing any errors. Solution to that was to be in that directory before executing it.
e.g.:
RUN source /home/ubuntu/canonicaliser_api/venv/bin/activate && cd /home/ubuntu/canonicaliser_api/canonicaliser/cython_extensions/ && python setup.py build_ext --inplace
The painful part about Docker seems that you have to chain all commmands as it seems to be stateless.

Categories

Resources