I'm following the tutorial for SWIG and Python, but I'm getting an error when I try to import the compiled extension in Python.
Python 3.5.2 (default, Oct 11 2016, 15:01:25)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
>>> import _example
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/pat/to/_example.cpython-35m-darwin.so, 2): Symbol not found: _fact
Referenced from: /path/to/_example.cpython-35m-darwin.so
Expected in: flat namespace
in /path/to/_example.cpython-35m-darwin.so
Note that the error says it can't find the symbol _fact. I'm not sure where the leading underscore is coming from, and I can't find any information about how to resolve this problem.
Here is example.i (matches what's in the tutorial):
%module example
%{
#define SWIG_FILE_WITH_INIT
#include "example.h"
%}
int fact(int n);
example.h and example.c also match what's in the tutorial; I can post here if necessary.
Here's setup.py:
# coding=utf-8
from setuptools import Extension, setup
setup(
name = 'SWIG Test',
ext_modules = [Extension('_example', ['example.i'])],
py_modules = ['example'],
)
This is the relevant output of pip install -e . -v:
running build_ext
building '_example' extension
swigging example.i to example_wrap.c
swig -python -o example_wrap.c example.i
creating build
creating build/temp.macosx-10.12-x86_64-3.5
/usr/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -pipe -Os -I/opt/local/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -c example_wrap.c -o build/temp.macosx-10.12-x86_64-3.5/example_wrap.o
creating build/lib.macosx-10.12-x86_64-3.5
/usr/bin/clang -bundle -undefined dynamic_lookup -L/opt/local/lib -Wl,-headerpad_max_install_names build/temp.macosx-10.12-x86_64-3.5/example_wrap.o -o build/lib.macosx-10.12-x86_64-3.5/_example.cpython-35m-darwin.so
copying build/lib.macosx-10.12-x86_64-3.5/_example.cpython-35m-darwin.so ->
Some things that I've tried that didn't work:
Declaring fact as int fact(int n) asm("fact") (after building, I get Symbol not found: fact when importing).
Adding swig_opts=['-py3'] to the extension in setup.py.
The leading underscore was a red herring. Turns out, I simply forgot to include example.c in my extension sources.
Here's what setup.py is supposed to look like:
# coding=utf-8
from setuptools import Extension, setup
setup(
name = 'SWIG Test',
ext_modules = [Extension('_example', ['example.i', 'example.c'])],
py_modules = ['example'],
)
Note that the extension has both example.i and example.c in its sources.
Now everything works as expected (:
Python 3.5.2 (default, Oct 11 2016, 15:01:25)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
>>> import example
>>> example.fact(42)
0
>>> example.fact(0)
1
Related
I am deeply frustrated by rolling-releases of Termux with no regard to previous python releases and modules
Now I am compiling latest got version of Scipy but before that I am running
export BLAS=/data/data/com.termux/files/usr/lib/libblas.so
export LAPACK=/data/data/com.termux/files/usr/lib/liblapack.so
export CC=clang
export CPP=clang++
python runtests.py -v
https://scipy.github.io/devdocs/dev/contributor/runtests.html
There were some missing packages which I installed via pip
Following is the output & I need help here
Building, see build.log...
... build in progress (0:01:00.279236 elapsed)
Running from SciPy source directory.
scipy/linalg/_generate_pyx.py: all files up-to-date
scipy/special/_generate_pyx.py: all files up-to-date
Running scipy/linalg/_generate_pyx.py
Running scipy/special/_generate_pyx.py
Running scipy/stats/_generate_pyx.py
scipy/_lib/_ccallback_c.pyx has not changed
scipy/_lib/_test_deprecation_call.pyx has not changed
scipy/_lib/messagestream.pyx has not changed
scipy/cluster/_hierarchy.pyx has not changed
scipy/_lib/_test_deprecation_def.pyx has not changed
scipy/cluster/_vq.pyx has not changed
scipy/fftpack/convolve.pyx has not changed
scipy/interpolate/_bspl.pyx has not changed
scipy/cluster/_optimal_leaf_ordering.pyx has not changed
scipy/interpolate/_ppoly.pyx has not changed
scipy/interpolate/interpnd.pyx has not changed
scipy/io/matlab/_mio5_utils.pyx has not changed
scipy/io/matlab/_mio_utils.pyx has not changed
scipy/io/matlab/_streams.pyx has not changed
scipy/linalg/_cythonized_array_utils.pyx has not changed
scipy/linalg/_decomp_update.pyx.in has not changed
scipy/linalg/_matfuncs_expm.pyx.in has not changed
scipy/linalg/_matfuncs_sqrtm_triu.pyx has not changed
scipy/linalg/cython_blas.pyx has not changed
scipy/linalg/_solve_toeplitz.pyx has not changed
scipy/linalg/cython_lapack.pyx has not changed
scipy/ndimage/src/_cytest.pyx has not changed
scipy/ndimage/src/_ni_label.pyx has not changed
scipy/optimize/_bglu_dense.pyx has not changed
scipy/optimize/_group_columns.pyx has not changed
scipy/optimize/_highs/cython/src/_highs_constants.pyx has not changed
scipy/optimize/_highs/cython/src/_highs_wrapper.pyx has not changed
scipy/optimize/_lsq/givens_elimination.pyx has not changed
scipy/optimize/_trlib/_trlib.pyx has not changed
scipy/optimize/cython_optimize/_zeros.pyx.in has not changed
scipy/optimize/tnc/_moduleTNC.pyx has not changed
scipy/signal/_max_len_seq_inner.pyx has not changed
scipy/signal/_peak_finding_utils.pyx has not changed
scipy/signal/_sosfilt.pyx has not changed
scipy/signal/_spectral.pyx has not changed
scipy/signal/_upfirdn_apply.pyx has not changed
scipy/sparse/_csparsetools.pyx.in has not changed
scipy/sparse/csgraph/_flow.pyx has not changed
scipy/sparse/csgraph/_matching.pyx has not changed
scipy/sparse/csgraph/_min_spanning_tree.pyx has not changed
scipy/sparse/csgraph/_reordering.pyx has not changed
scipy/sparse/csgraph/_shortest_path.pyx has not changed
scipy/sparse/csgraph/_tools.pyx has not changed
scipy/sparse/csgraph/_traversal.pyx has not changed
scipy/spatial/_ckdtree.pyx has not changed
scipy/spatial/_hausdorff.pyx has not changed
scipy/spatial/_qhull.pyx has not changed
scipy/spatial/_voronoi.pyx has not changed
scipy/spatial/transform/_rotation.pyx has not changed
scipy/special/_comb.pyx has not changed
scipy/special/_ellip_harm_2.pyx has not changed
scipy/special/_test_round.pyx has not changed
scipy/special/_ufuncs.pyx has not changed
scipy/special/_ufuncs_cxx.pyx has not changed
scipy/special/cython_special.pyx has not changed
scipy/stats/_qmc_cy.pyx has not changed
scipy/stats/_sobol.pyx has not changed
scipy/stats/_biasedurn.pyx has not changed
scipy/stats/_stats.pyx has not changed
scipy/stats/_boost/src/beta_ufunc.pyx has not changed
scipy/stats/_boost/src/nbinom_ufunc.pyx has not changed
scipy/stats/_boost/src/binom_ufunc.pyx has not changed
scipy/stats/_boost/src/hypergeom_ufunc.pyx has not changed
scipy/stats/_boost/src/ncf_ufunc.pyx has not changed
scipy/stats/_levy_stable/levyst.pyx has not changed
scipy/stats/_unuran/unuran_wrapper.pyx has not changed
/data/data/com.termux/files/usr/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py:102: _ExperimentalProjectMetadata: Support for project metadata in `pyproject.toml` is still experimental and may be removed (or change) in future releases.
warnings.warn(msg, _ExperimentalProjectMetadata)
Cythonizing sources
INFO: lapack_opt_info:
INFO: lapack_armpl_info:
INFO: customize UnixCCompiler
INFO: libraries armpl_lp64_mp not found in ['/data/data/com.termux/files/usr/lib']
INFO: NOT AVAILABLE
INFO:
INFO: lapack_mkl_info:
INFO: libraries mkl_rt not found in ['/data/data/com.termux/files/usr/lib']
INFO: NOT AVAILABLE
INFO:
INFO: openblas_lapack_info:
INFO: C compiler: clang -mfloat-abi=softfp -mfpu=vfpv3-d16 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb -fstack-protector-strong -O3 -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb -fstack-protector-strong -O3 -fPIC
creating /data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/data
creating /data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/data/data
creating /data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/data/data/com.termux
creating /data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/data/data/com.termux/files
creating /data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/data/data/com.termux/files/usr
creating /data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/data/data/com.termux/files/usr/tmp
creating /data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/data/data/com.termux/files/usr/tmp/tmpw9i7rrqz
INFO: compile options: '-c'
INFO: clang: /data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/source.c
INFO: clang /data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/source.o -L/data/data/com.termux/files/usr/lib -lopenblas -o /data/data/com.termux/files/usr/tmp/tmpw9i7rrqz/a.out
INFO: FOUND:
INFO: libraries = ['openblas', 'openblas']
INFO: library_dirs = ['/data/data/com.termux/files/usr/lib']
INFO: language = c
INFO: define_macros = [('HAVE_CBLAS', None)]
INFO:
INFO: FOUND:
INFO: libraries = ['openblas', 'openblas']
INFO: library_dirs = ['/data/data/com.termux/files/usr/lib']
INFO: language = c
INFO: define_macros = [('HAVE_CBLAS', None)]
INFO:
non-existing path in 'scipy/linalg': 'src/lapack_deprecations/LICENSE'
INFO: blas_opt_info:
INFO: blas_armpl_info:
INFO: libraries armpl_lp64_mp not found in ['/data/data/com.termux/files/usr/lib']
INFO: NOT AVAILABLE
INFO:
INFO: blas_mkl_info:
INFO: libraries mkl_rt not found in ['/data/data/com.termux/files/usr/lib']
INFO: NOT AVAILABLE
INFO:
INFO: blis_info:
INFO: libraries blis not found in ['/data/data/com.termux/files/usr/lib']
INFO: NOT AVAILABLE
INFO:
INFO: openblas_info:
INFO: C compiler: clang -mfloat-abi=softfp -mfpu=vfpv3-d16 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb -fstack-protector-strong -O3 -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb -fstack-protector-strong -O3 -fPIC
creating /data/data/com.termux/files/usr/tmp/tmp0139l74e/data
creating /data/data/com.termux/files/usr/tmp/tmp0139l74e/data/data
creating /data/data/com.termux/files/usr/tmp/tmp0139l74e/data/data/com.termux
creating /data/data/com.termux/files/usr/tmp/tmp0139l74e/data/data/com.termux/files
creating /data/data/com.termux/files/usr/tmp/tmp0139l74e/data/data/com.termux/files/usr
creating /data/data/com.termux/files/usr/tmp/tmp0139l74e/data/data/com.termux/files/usr/tmp
creating /data/data/com.termux/files/usr/tmp/tmp0139l74e/data/data/com.termux/files/usr/tmp/tmp0139l74e
INFO: compile options: '-c'
INFO: clang: /data/data/com.termux/files/usr/tmp/tmp0139l74e/source.c
INFO: clang /data/data/com.termux/files/usr/tmp/tmp0139l74e/data/data/com.termux/files/usr/tmp/tmp0139l74e/source.o -L/data/data/com.termux/files/usr/lib -lopenblas -o /data/data/com.termux/files/usr/tmp/tmp0139l74e/a.out
INFO: FOUND:
INFO: libraries = ['openblas', 'openblas']
INFO: library_dirs = ['/data/data/com.termux/files/usr/lib']
INFO: language = c
INFO: define_macros = [('HAVE_CBLAS', None)]
INFO:
INFO: FOUND:
INFO: libraries = ['openblas', 'openblas']
INFO: library_dirs = ['/data/data/com.termux/files/usr/lib']
INFO: language = c
INFO: define_macros = [('HAVE_CBLAS', None)]
INFO:
Traceback (most recent call last):
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/scipy/setup.py", line 532, in <module>
setup_package()
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/scipy/setup.py", line 528, in setup_package
setup(**metadata)
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/numpy/distutils/core.py", line 135, in setup
config = configuration()
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/scipy/setup.py", line 438, in configuration
config.add_subpackage('scipy')
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 1054, in add_subpackage
config_list = self.get_subpackage(subpackage_name, subpackage_path,
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 1020, in get_subpackage
config = self._get_configuration_from_setup_py(
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 962, in _get_configuration_from_setup_py
config = setup_module.configuration(*args)
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/scipy/scipy/setup.py", line 18, in configuration
config.add_subpackage('optimize')
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 1054, in add_subpackage
config_list = self.get_subpackage(subpackage_name, subpackage_path,
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 1020, in get_subpackage
config = self._get_configuration_from_setup_py(
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 962, in _get_configuration_from_setup_py
config = setup_module.configuration(*args)
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/scipy/scipy/optimize/setup.py", line 130, in configuration
config.add_subpackage('_highs')
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 1054, in add_subpackage
config_list = self.get_subpackage(subpackage_name, subpackage_path,
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 1020, in get_subpackage
config = self._get_configuration_from_setup_py(
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 962, in _get_configuration_from_setup_py
config = setup_module.configuration(*args)
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/scipy/scipy/optimize/_highs/setup.py", line 63, in configuration
_major_dot_minor = _get_version(
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/scipy/scipy/optimize/_highs/setup.py", line 50, in _get_version
with open(CMakeLists, 'r', encoding='utf-8') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/data/data/com.termux/files/usr/lib/python3.10/site-packages/scipy/scipy/_lib/highs/CMakeLists.txt'
Build failed! (0:01:17.306152 elapsed)
Clean Install Termux on Samsung Z Flip 4
https://www.youtube.com/watch?v=yDwxmF0Kn-Q
update
upgrade
apt install python (3.11.1 was installed)
To manage and access files in termux then you must type the below command
termux-setup-storage
pkg install tur-repo
pkg install python-scipy
connected phone via usb to a computer and copied my python scripts to phone downloads folder
cp ~/storage/downloads/file.py ~/ to run programs from termux home.
You get Deprecation Warnings for interp2d which will be replaced in scipy
so add to stop them at the top.
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
The end. ps
All woks fine and tested on 2d interpolation arrays.
I assume that what you want is the latest version of Scipy working in Termux.
I think you are making it difficult for yourself.
I managed to compile and install scipy 1.8.1 correctly for python 3.10.4 using only Termux.
First, get rid of all exports before installation. As a side note, if no CC env. variable is set, pip will use aarch64-linux-android-clang by default.
You don't need libblas.so and liblapack.so either.
It is indeed necessary to have the BLAS/LAPACK libraries when compiling Scipy, but you can simply get them by pkg in openblas.
Once done, a simple pip install scipy worked like a charm for me (it took me more than 15 minutes to build it, so be patient).
Hope it helps you ^^
Although I was unable to install Scipy via pip for Python 3.11, which is the current version used in Termux as of today, I managed to build Scipy 1.9.0 and install it manually.
Apart from some dependencies I installed via pkg, which were requested by the build system, such as pytest, I had to try with different versions of pip-installed libraries. The required libraries and versions that worked were:
beniget==0.4.1
Cython==0.29.32
distro==1.8.0
gast==0.5.3
meson==0.62.2
meson-python==0.7.0
mpmath==1.2.1
ninja==1.11.1
numpy==1.23.5
packaging==21.3
pip==22.3.1
ply==3.11
pybind11==2.9.2
pyparsing==3.0.9
pyproject-metadata==0.6.1
pythran==0.11.0
scikit-build==0.16.2
setuptools==65.6.3
tomli==2.0.1
wheel==0.37.1
I'm not sure if all of them are required. With them installed, I obtained the sources tarball for scipy-1.9.0, uncompressed it, and executed runtests.py (found in the root of the uncompressed tree).
After this, a working build of scipy was created in "build/lib.linux-aarch64-cpython-311/scipy", I copied it to the system package directory: "/data/data/com.termux/files/home/../usr/lib/python3.11/site-packages/", and now I can use scipy again.
Because debian stretch have old package of gobject-introspection,i needed to update this.
But when i tryed to build, i got next message:
FAILED: gir/GLib-2.0.gir
/home/user/gobject-introspection-1.70.0/_build/tools/g-ir-scanner --output=gir/GLib-2.0.gir --no-libtool --quiet --reparse-validate --add-include-path /home/user/gobject-introspection-1.70.0/_build/gir --add-include-path /home/user/gobject-introspection-1.70.0/gir --identifier-prefix=G --symbol-prefix=g --symbol-prefix=glib --c-include=glib.h --namespace=GLib --nsversion=2.0 --library=glib-2.0 --library=gobject-2.0 --external-library --pkg=glib-2.0 --cflags-begin -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -DGLIB_COMPILATION -D__G_I18N_LIB_H__ -DGETTEXT_PACKAGE=Dummy --cflags-end /usr/include/glib-2.0/gobject/glib-types.h /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h /usr/include/glib-2.0/glib-unix.h /usr/include/glib-2.0/glib/galloca.h /usr/include/glib-2.0/glib/garray.h /usr/include/glib-2.0/glib/gasyncqueue.h /usr/include/glib-2.0/glib/gatomic.h /usr/include/glib-2.0/glib/gbacktrace.h /usr/include/glib-2.0/glib/gbase64.h /usr/include/glib-2.0/glib/gbitlock.h /usr/include/glib-2.0/glib/gbookmarkfile.h /usr/include/glib-2.0/glib/gbytes.h /usr/include/glib-2.0/glib/gcharset.h /usr/include/glib-2.0/glib/gchecksum.h /usr/include/glib-2.0/glib/gconvert.h /usr/include/glib-2.0/glib/gdataset.h /usr/include/glib-2.0/glib/gdate.h /usr/include/glib-2.0/glib/gdatetime.h /usr/include/glib-2.0/glib/gdir.h /usr/include/glib-2.0/glib/genviron.h /usr/include/glib-2.0/glib/gerror.h /usr/include/glib-2.0/glib/gfileutils.h /usr/include/glib-2.0/glib/ggettext.h /usr/include/glib-2.0/glib/ghash.h /usr/include/glib-2.0/glib/ghmac.h /usr/include/glib-2.0/glib/ghook.h /usr/include/glib-2.0/glib/ghostutils.h /usr/include/glib-2.0/glib/gi18n-lib.h /usr/include/glib-2.0/glib/gi18n.h /usr/include/glib-2.0/glib/giochannel.h /usr/include/glib-2.0/glib/gkeyfile.h /usr/include/glib-2.0/glib/glib-typeof.h /usr/include/glib-2.0/glib/glist.h /usr/include/glib-2.0/glib/gmacros.h /usr/include/glib-2.0/glib/gmain.h /usr/include/glib-2.0/glib/gmappedfile.h /usr/include/glib-2.0/glib/gmarkup.h /usr/include/glib-2.0/glib/gmem.h /usr/include/glib-2.0/glib/gmessages.h /usr/include/glib-2.0/glib/gnode.h /usr/include/glib-2.0/glib/goption.h /usr/include/glib-2.0/glib/gpattern.h /usr/include/glib-2.0/glib/gpoll.h /usr/include/glib-2.0/glib/gprimes.h /usr/include/glib-2.0/glib/gprintf.h /usr/include/glib-2.0/glib/gqsort.h /usr/include/glib-2.0/glib/gquark.h /usr/include/glib-2.0/glib/gqueue.h /usr/include/glib-2.0/glib/grand.h /usr/include/glib-2.0/glib/grcbox.h /usr/include/glib-2.0/glib/grefcount.h /usr/include/glib-2.0/glib/grefstring.h /usr/include/glib-2.0/glib/gregex.h /usr/include/glib-2.0/glib/gscanner.h /usr/include/glib-2.0/glib/gsequence.h /usr/include/glib-2.0/glib/gshell.h /usr/include/glib-2.0/glib/gslice.h /usr/include/glib-2.0/glib/gslist.h /usr/include/glib-2.0/glib/gspawn.h /usr/include/glib-2.0/glib/gstdio.h /usr/include/glib-2.0/glib/gstrfuncs.h /usr/include/glib-2.0/glib/gstring.h /usr/include/glib-2.0/glib/gstringchunk.h /usr/include/glib-2.0/glib/gstrvbuilder.h /usr/include/glib-2.0/glib/gtestutils.h /usr/include/glib-2.0/glib/gthread.h /usr/include/glib-2.0/glib/gthreadpool.h /usr/include/glib-2.0/glib/gtimer.h /usr/include/glib-2.0/glib/gtimezone.h /usr/include/glib-2.0/glib/gtrashstack.h /usr/include/glib-2.0/glib/gtree.h /usr/include/glib-2.0/glib/gtypes.h /usr/include/glib-2.0/glib/gunicode.h /usr/include/glib-2.0/glib/guri.h /usr/include/glib-2.0/glib/gurifuncs.h /usr/include/glib-2.0/glib/gutils.h /usr/include/glib-2.0/glib/guuid.h /usr/include/glib-2.0/glib/gvariant.h /usr/include/glib-2.0/glib/gvarianttype.h /usr/include/glib-2.0/glib/gversion.h /usr/include/glib-2.0/glib/gversionmacros.h /usr/include/glib-2.0/glib/gwin32.h ../gir/glib-2.0.c
Traceback (most recent call last):
File "/home/user/gobject-introspection-1.70.0/_build/tools/g-ir-scanner", line 98, in <module>
from giscanner.scannermain import scanner_main
File "/home/user/gobject-introspection-1.70.0/_build/giscanner/scannermain.py", line 35, in <module>
from giscanner.ast import Include, Namespace
File "/home/user/gobject-introspection-1.70.0/_build/giscanner/ast.py", line 29, in <module>
from .sourcescanner import CTYPE_TYPEDEF, CSYMBOL_TYPE_TYPEDEF
File "/home/user/gobject-introspection-1.70.0/_build/giscanner/sourcescanner.py", line 34, in <module>
from giscanner._giscanner import SourceScanner as CSourceScanner
ImportError: /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined symbol: g_date_copy
I know about required version glib >= 2.56.
I build it too and install from latest(2.70) source, but the error remains.
user#debian-stretch:/usr/lib/x86_64-linux-gnu$ cat /usr/lib/x86_64-linux-gnu/pkgconfig /gobject-2.0.pc
prefix=/usr
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include
Name: GObject
Description: GLib Type, Object, Parameter and Signal Library
Version: 2.70.0
Requires: glib-2.0
Requires.private: libffi >= 3.0.0
Libs: -L${libdir} -lgobject-2.0
Cflags: -I${includedir}
user#debian-stretch:/usr/lib/x86_64-linux-gnu$ cat /usr/lib/x86_64-linux-gnu/pkgconfig /glib-2.0.pc
prefix=/usr
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include
bindir=${prefix}/bin
glib_genmarshal=${bindir}/glib-genmarshal
gobject_query=${bindir}/gobject-query
glib_mkenums=${bindir}/glib-mkenums
Name: GLib
Description: C Utility Library
Version: 2.70.0
Requires.private: libpcre >= 8.31
Libs: -L${libdir} -lglib-2.0
Libs.private: -pthread -lm
Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include
Can you help with it trouble?
UPD
i read again this post and i had seen next thing:
default libglib2.0-0 package install some libs on to another path, in: /lib/x86_64-linux-gnu/
After that i tryed find it's on my instance, and got next out:
user#debian-stretch:~$ sudo find / -iname '*glib-2.0.*'
/usr/lib/x86_64-linux-gnu/libglib-2.0.so
/usr/lib/x86_64-linux-gnu/girepository-1.0/GLib-2.0.typelib
/usr/lib/x86_64-linux-gnu/pkgconfig/glib-2.0.pc
/usr/lib/x86_64-linux-gnu/libglib-2.0.a
/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7000.0
/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7000.0-gdb.py
/usr/share/gir-1.0/GLib-2.0.gir
/usr/share/aclocal/glib-2.0.m4
/usr/local/share/gdb/auto-load/usr/local/lib/x86_64-linux-gnu/libglib-2.0.so.0.7000.0-gdb.py
/usr/local/share/aclocal/glib-2.0.m4
/lib/x86_64-linux-gnu/libglib-2.0.so.0.5000.3
/lib/x86_64-linux-gnu/libglib-2.0.so.0
/home/user/glib-2.70.0/m4macros/glib-2.0.m4
/home/user/glib-2.70.0/_build/glib/libglib-2.0.so.0.7000.0.p
/home/user/glib-2.70.0/_build/glib/libglib-2.0.so
/home/user/glib-2.70.0/_build/glib/libglib-2.0.so.0.7000.0-gdb.py
/home/user/glib-2.70.0/_build/glib/libglib-2.0.so.0
/home/user/glib-2.70.0/_build/meson-private/glib-2.0.pc
/home/user/gobject-introspection-1.70.0/gir/glib-2.0.c
/home/user/gobject-introspection-1.70.0/subprojects/glib/m4macros/glib-2.0.m4
/home/user/packaging-glib/glib-2.70.0/usr/lib/x86_64-linux-gnu/libglib-2.0.so
/home/user/packaging-glib/glib-2.70.0/usr/lib/x86_64-linux-gnu/pkgconfig/glib-2.0.pc
/home/user/packaging-glib/glib-2.70.0/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7000.0
/home/user/packaging-glib/glib-2.70.0/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
/home/user/packaging-glib/glib-2.70.0/usr/share/aclocal/glib-2.0.m4
After remove this libs:
/lib/x86_64-linux-gnu/libglib-2.0.so.0.5000.3
/lib/x86_64-linux-gnu/libglib-2.0.so.0
building continue.
Definitely don't delete the GLib libraries in /lib. Since your package manager installed them there, other packages may expect to find them there, and so this may break your system down the line. (And since Debian Stretch is so old, with a GLib version of 2.50, it may even cause problems if you install GLib 2.70 systemwide.)
If you must install 2.70 systemwide, then I'd recommend building it with exactly the same configuration as the system version would. You can find the standard configuration options here and the options specific to GLib here. The options for gobject-introspection you can find in a similar place.
Even better, if you need to develop something using a GLib and gobject-introspection version that is not supported on your host system, would be to use some form of container technology. Either a runtime like Flatpak, or a "pet container" with a development environment, like Toolbox.
I'm starting to play with the library pybind11. It's really good library, well documented and it works for me but only with Python 2.7. I'm not able to get it working for Python 3.5 and I don't know what I'm doing wrong.
This is my "hello world" program:
#include <pybind11/pybind11.h>
namespace py = pybind11;
const char * world() { return "Hello world!"; }
int main(int argc, char ** argv) {
Py_Initialize();
py::module m("hello", "my hello world Python module with pybind11");
m.def("world", &world);
PyRun_SimpleString("import hello\nprint( hello.world() )");
Py_Finalize();
return 0;
}
If I compile and link against 2.7, I get the expected result:
Hello world!
But if I link exactly the same code with Python 3.5, I get an error loading the module.
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'hello'
Any ideas?
How did you compile the library and what system are you on? If you used python-config as suggested in the basic example in their documentation (the command below), you'll compile against the development version on your machine.
c++ -O3 -shared -std=c++11 -I <path-to-pybind11>/include `python-config --cflags --ldflags` example.cpp -o example.so
This is likely Python 2.7 even if you use Python 3.5. In my case, I used Anaconda to install python, and that gave me Python 3.5, but the system Python is still 2.7.
What does python-config give you? Is the version listed Python 3.5? If it is not you cannot use this command at least without modifications. What you can do is cmake build system as described in their documentation. That fixed it for me. Using their setuptools system, would probably also work. Basically, they figure out what you used to compile their library and use those flags. This does mean, that you have to make sure that you are linking against Python 3.5 when building the library itself.
I am using Anacondas on a 64-bit Windows machine.
I have compiled a hello world Cython example. It is in file hello.pyx, and contains:
def say_hello_to(name):
print("Hello %s!" % name)
I am running it using run_hello.py
import pyximport; pyximport.install()
import hello as hello
hello.say_hello_to('jon')
The setup file is setup.py:
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = 'Hello world app',
ext_modules = cythonize("hello.pyx"),
)
I am then compiling the code in Python 3.3 on Anacondas, using this code:
> activate py33
> python setup.py build_ext --inplace
( please note that py33 is my Python 3.3 environment )
I can then run the example:
python run_hello.py
which prints out "Hello jon!" as expected.
Now if I change my environment to Python 3.4 and compile:
> activate py34
> python setup.py build_ext --inplace
I get no error, and the shell displays
running build_ext
However, if I try to run run_hello.py from the py34 environment with:
python run_hello.py
I get:
Traceback (most recent call last):
File "run_hello.py", line 2, in <module>
import hello as hello
ImportError: DLL load failed: The specified module could not be found.
The error is not very descriptive. What could I do to help me make this work on Python 3.4?
If I delete hello.c and the /build folder from my hard drive, trying to compile from Python 3.4 returns:
Compiling hello.pyx because it changed.
Cythonizing hello.pyx
running build_ext
building 'hello' extension
creating build
creating build\temp.win-amd64-3.4
creating build\temp.win-amd64-3.4\Release
C:\Anaconda\envs\py34\Scripts\gcc.bat -mdll -O -Wall -IC:\Anaconda\envs\py34\include -IC:\Anaconda\envs\py34\include -c hello.c -o build\temp.win-amd64-3.4\Release\hello.o
writing build\temp.win-amd64-3.4\Release\hello.def
C:\Anaconda\envs\py34\Scripts\gcc.bat -shared -s build\temp.win-amd64-3.4\Release\hello.o build\temp.win-amd64-3.4\Release\hello.def -LC:\Anaconda\envs\py34\libs -LC:\Anaconda\envs\py34\PCbuild\amd64
-lpython34 -lmsvcr100 -o c:\Users\Jon\Documents\GitHub\CythonFunctions\example1\hello.pyd
build\temp.win-amd64-3.4\Release\hello.o:hello.c:(.text+0x314): undefined reference to `__imp__PyThreadState_Current'
build\temp.win-amd64-3.4\Release\hello.o:hello.c:(.text+0x493): undefined reference to `__imp__Py_NoneStruct'
build\temp.win-amd64-3.4\Release\hello.o:hello.c:(.text+0x97b): undefined reference to `__imp_PyExc_ImportError'
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\Anaconda\\envs\\py34\\Scripts\\gcc.bat' failed with exit status 1
If I do the same with Python 3.3, I get:
Compiling hello.pyx because it changed.
Cythonizing hello.pyx
running build_ext
building 'hello' extension
creating build
creating build\temp.win-amd64-3.3
creating build\temp.win-amd64-3.3\Release
C:\Anaconda\envs\py33\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -IC:\Anaconda\envs\py33\include -IC:\Anaconda\envs\py33\include -c hello.c -o build\temp.win-amd64-3.3\Release\hello.o
writing build\temp.win-amd64-3.3\Release\hello.def
C:\Anaconda\envs\py33\Scripts\gcc.bat -DMS_WIN64 -shared -s build\temp.win-amd64-3.3\Release\hello.o build\temp.win-amd64-3.3\Release\hello.def -LC:\Anaconda\envs\py33\libs -LC:\Anaconda\envs\py33\PCb
uild\amd64 -lpython33 -lmsvcr100 -o c:\Users\Jon\Documents\GitHub\CythonFunctions\example1\hello.pyd
Some other users who experience the "gcc.bat failed with exit status 1" have found that the problem is due to 32/64 bit conflicts.
In the py33 version of the compilation data, there is -DMS_WIN64 in the gcc.bat parameters, but it is not in the py34 parameters. Could that be what is causing my issue? If so, how do I get py34 to add it?
I had been using TDM-GCC as the 64-bit compiler with Python 2.7 64-bit for several years without any problems, but after installing Python 3.4 64-bit, I did have problems compiling a Cython module.
I believe I fixed this issue with mingw-w64-for-python. (Also take a look at this github issue).
There is a readme (currently mingwpy-2015-04-readme.pdf), so it is straightforward. But briefly you need to do:
Download mingwpy x86-64 toolchain (64 bit) (currently mingw64static-2014-11.tar.xz)
Unpack the file into a directory (e.g., C:\mingw64static)
Add C:\mingw64static\bin in front of C:\Anaconda3\Scripts in your Path
environmental variable.
Follow the instructions in the readme file to download libpython. (I used
libpython-cp34-none-win_amd64.7z for Python 3.4 64 bit)
Unpack, and copy files (libmsvcr100.a, libpython34.dll.a) in the archive into C:\Python\libs\ directory (for Anaconda, it is C:\Anaconda3\libs)
Create a file called distutils.cfg in your C:\Python\Lib\distutils
directory (for Anaconda, it is C:\Anaconda3\Lib\distutils) with the
following contents:
[build]
compiler=mingw32
Now python will correctly use mingw-w64 when you compile your cython module.
It looks like the py33 environment is compiling using Visual Studio (-lmsvcr100). This is probably because it doesn't have the libpython conda package installed in it, which causes distutils to use mingw (gcc) to compile instead of Visual Studio. conda remove libpython will likely solve the issue for your Python 3.4 environment.
I'm trying to install Biopython 1.61. I'm logged in as root in a bash terminal. I'm using Mageia 2.0, and I've updated all the packages/programs on the OS (with urpmi update -a).
I extracted the source, then ran python setup.py build, which had two errors:
FAIL: test_protein_16130152 (test_SeqIO_online.EntrezTests)
Bio.Entrez.efetch(protein, 16130152, ...)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_online.py", line 77, in <lambda>
method = lambda x : x.simple(d, f, e, l, c)
File "test_SeqIO_online.py", line 65, in simple
self.assertEqual(seguid(record.seq), checksum)
AssertionError: 'NT/aFiTXyD/7KixizZ9sq2FcniU' != 'fCjcjMFeGIrilHAn6h+yju267lg'
======================================================================
ERROR: test_doctests (test_Tutorial.TutorialTestCase)
Run tutorial doctests.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_Tutorial.py", line 152, in test_doctests
ValueError: 4 Tutorial doctests failed: test_from_line_05671, test_from_line_06030, test_from_line_06190, test_from_line_06479
Then I ran python setup.py install, but it failed, too. I updated my python with (urpmi install lib64python-devel) and my gcc, but it was already up to date.
This is the error I get from python setup.py install:
[root#localhost biopython-1.61]# python setup.py install
running install
running build
running build_py
warning: build_py_biopython: byte-compiling is disabled, skipping.
running build_ext
building 'Bio.Cluster.cluster' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -I/usr/include/ncursesw -DNDEBUG -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -g -fPIC -I/usr/lib64/python2.7/site-packages/numpy/core/include -I/usr/include/python2.7 -c Bio/Cluster/clustermodule.c -o build/temp.linux-x86_64-2.7/Bio/Cluster/clustermodule.o
Bio/Cluster/clustermodule.c:2:31: fatal error: numpy/arrayobject.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
The unit test failures have been fixed in Biopython itself.
The compiler error suggests you are missing the NumPy header files, often included in the OS package manager in a separate package called something like numpy-dev or numpy-devel.