Building a ctypes-“based” C library with distutils

The distutils documentation here states that: A C extension for CPython is a shared library (e.g. a .so file on Linux, .pyd on Windows), which exports an initialization function. So the only difference regarding a plain shared library seems to be the initialization function (besides a sensible file naming convention I don’t think you have … Read more

Is there a version of TensorFlow not compiled for AVX instructions?

A best practices approach suggested by peter-cordes is to see what gcc is going to make of your ‘what capabilities your cpu has’ by issuing the following: gcc -O3 -fverbose-asm -march=native -xc /dev/null -S -o- | less This command will provide information (all) about your cpu capabilities from the view of gcc, whom is going … Read more

Cannot load backend ‘Qt5Agg’ which requires the ‘qt5’ interactive framework, as ‘headless’ is currently running

This is happening because Google Colab and Jupyter run on virtual environments which do not support GUI outputs as you cannot open new windows through a browser. Running it locally on a code editor(Spyder, or even IDLE) ensures that it can open a new window for the GUI to initialize. For coding the GUI it … Read more

Rasterizing a GDAL layer

EDIT: I guess I’d use qGIS python bindings: http://www.qgis.org/wiki/Python_Bindings That’s the easiest way I can think of. I remember hand rolling something before, but it’s ugly. qGIS would be easier, even if you had to make a separate Windows installation (to get python to work with it) then set up an XML-RPC server to run … Read more

argparse action or type for comma-separated list

The simplest solution is to consider your argument as a string and split. #!/usr/bin/env python3 import argparse parser = argparse.ArgumentParser() parser.add_argument(“–myarg”, type=str) args = parser.parse_args() if args.myarg is not None: args.myarg = [s.strip() for s in args.myarg.split(“,”)] print(args) Result: $ ./toto.py –myarg=abcd,e,fg Namespace(myarg=[‘abcd’, ‘e’, ‘fg’]) $ ./toto.py –myarg=”abcd, e, fg” Namespace(myarg=[‘abcd’, ‘e’, ‘fg’])

Must have equal len keys and value when setting with an iterable

You can use apply to index into leader and exchange values with DatasetLabel, although it’s not very pretty. One issue is that Pandas won’t let us index with NaN. Converting to str provides a workaround. But that creates a second issue, namely, column 9 is of type float (because NaN is float), so 5 becomes … Read more

Any python function to get “data_files” root directory?

By default, when installing a package as root, relative directory names in the data_files list are are resolved against either the value of sys.prefix (for pure-python libraries) or sys.exec_prefix (for libraries with a compiled extension), so you can retrieve your files based on that. Qouting from the distutils documentation: If directory is a relative path, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)