Pybind11 build with poetry - static-libraries

I am currently trying to build a small pybind11 extension and to integrate smoothly with our current setup, it would be neat if that would work with poetry build && poetry install
from pybind11.setup_helpers import Pybind11Extension, build_ext
def build(setup_kwargs):
ext_modules = [
Pybind11Extension(
"my_module",
["folder/one.cpp", "folder/another.cpp"],
include_dirs=[".", "my_static_lib/include/"],
extra_compile_args=['-O3', '-pthread'],
language='c++',
cxx_std=11
),
]
setup_kwargs.update({
"ext_modules": ext_modules,
"cmd_class": {"build_ext": build_ext},
"zip_safe": False,
})
That compiles all fine, but since I don't know how to inform the linker about the static library that I depend on, I have undefined symbols when I load the package.
Any idea how that works?
Is this an odd thing to try?
Thanks for your help or comments!

It was actually quite simple, I just did not find the documentation anywhere. There is an argument called "extra_link_args", where I can specify all these things:
def build(setup_kwargs):
ext_modules = [
Pybind11Extension(
"my_module",
["folder/one.cpp", "folder/another.cpp"],
include_dirs=[".", "my_static_lib/include/"],
extra_compile_args=['-O3'],
extra_link_args=['my_static_lib/libmystatic.a', '-lbz2', '-pthread'],
language='c++',
cxx_std=11
),
]
setup_kwargs.update({
"ext_modules": ext_modules,
"cmd_class": {"build_ext": build_ext},
"zip_safe": False,
})
I still haven't figured out how do specify the compiler, but fortunately, it works for now with the default compiler on my mac.

Related

Writing out document in GUI executable using cx_freeze not working

I made an executable gui (with tkinter) file using cx_freeze. The executable has several buttons. When the user click the button, the calculation should work and then it will write out an xlsx file.
Everything went good when I make the executable, there was no error. But when I click the button, it seems like the calculation works (since it was loading), but then it does not write out the xlsx file.
I don't know what went wrong. Anyone can help me?
Here's the setup.py file:
import sys
from cx_Freeze import setup, Executable
import os
import tkinter
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [Executable("gui.py", base=base)]
packages = ["tkinter", 'xlsxwriter', 'matplotlib']
options = {
'build_exe': {
'includes': ["os", "tkinter", 'numpy.core._methods', 'numpy.lib.format', 'xlrd', 'scipy', 'pandas'],
'include_files': [r"C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\DLLs\tcl86t.dll",
r"C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\DLLs\tk86t.dll"]
},
}
os.environ['TCL_LIBRARY'] = r'C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
setup(
name="Tool",
version="1.0",
description="Tool prototype for calculating",
options=options,
executables=executables
)
I've solved the problem.
What i did was to change the base in setup.py to : base = None
and I installed the xlsxwriter by following this thread: ImportError: No module named 'xlsxwriter': Error in bamboo
After this, I encountered another problem:
No module named: scipy.sparse.csgraph._validation
but I simply add this to the 'includes': ['scipy.sparse.csgraph._validation', ...]
now everything works perfectly.
I hope this helps anyone who has the same problem.

Compile error but js get generated

This is a new computer setup. All code compile and run on my old comupter.
I have 2 project in my solution than use typescript.
The first compile without problem.
The second one show error on compile but generate js on save.
I have installed vs 2013 update 5 then installed typescript 1.8.5.
I alsow have vs2015 installed.
After vs2015 was installed i have repair the typescript sdk.
They must have 2 different compiler setup and one in my project is not set correctly.
I have dig into the csproj and compare the 2 project but did not find missing/different parameter for typescript ....
It's like it dont take the new version. I get syntax errors in code i know it compile.
if someone had this problem, please help me.
p.s excuse me for my bad english, im french ...
UPDATE: Exemple of code dont compile
public doSomething(errorCallBack?: (failCallback1?: JQueryPromiseCallback<any> | JQueryPromiseCallback<any>[], ...failCallbacksN: Array<JQueryPromiseCallback<any> | JQueryPromiseCallback<any>[]>) => void)
{}
Error :
Error 218 Build: ',' expected.
A reduced sample code that fails to compile:
class Foo {
public doSomething(errorCallBack?: (failCallback1?: any, ...failCallbacksN: Array<any>[]>) => void)
{ }
}
You have major syntax errors in ...failCallbacksN: Array<any>[]>. You need something like ...failCallbacksN: Array<any> e.g.:
class Foo {
public doSomething(errorCallBack?: (failCallback1?: any, ...failCallbacksN: Array<any>) => void)
{ }
}
but js get generated
This is by design. Valid JavaScript will always generate valid TypeScript (even in the presence of errors). The types are considered invisible to the emitter in TypeScript so even in the presence of type errors TypeScript will try and do graceful recovery and generate JavaScript.
More
See Why TypeScript : https://basarat.gitbooks.io/typescript/content/docs/why-typescript.html
I have found than visual studio IDE was using 1.8.9 and the compiler was 1.0. This is why i had such compilation errors.
when i used "tsc -v" command in vs2013 command prompt, it show 1.0.
when i use "where tsc" it show only directory for 1.0 and not the 1.8.9.
so, i have replaced the 1.0 content with 1.8.9 . I dont use 1.0.
Now i have a 1.0 directory wish have 1.8.9 in it.
I think this is not the way it's supposed to be, but i need it to work.
It have a .target file i can modify, but i dont wish to do that.

Add angular-material to mean.io app

I'm trying to add angular-material to a mean.io application.
I have, in my custom package, used bower to install angular-material and now I have a .../public/assets/lib/angular-material folder.
So far so good. Now I want to use it in my custom mean.io module and according to their documentation I have added
MyPackage.angularDependencies(['ngMaterial']);
in my app.js file.
I have also aggregated angular-material.css and angular-material.js (not sure if this should be needed).
But, I get the following error:
Failed to instantiate module mean due to:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=m...)
at Error (native)
at http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:6:416
at http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:38:391
at n (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:7:333)
at g (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:37:488)
at http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:38:134
at n (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:7:333)
at g (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:37:488)
at eb (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:41:249)
at c (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:19:463
I'm assuming mean doesn't find the angular-material module and I need to specify its path somewhere. But I can't figure out where.
I had the same problem, this is happening because angular couldn't resolve some required libraries by material, I didn't get so deep into this investigation but I found an alternative solution as described below:
Navigate to the project root directory and then install angular material using bower:
$ bower install angular-material --save
Then, into the project root directory you will find the /config/assets.json file where AngularJS is included, now you add the angular material libraries like this:
{
"core": {
"css": {
"bower_components/build/css/dist.min.css": [
"bower_components/angular/angular-csp.css",
-> "bower_components/angular-material/angular-material.css",
"bower_components/angular-ui-select/dist/select.min.css"
]
},
"js": {
"bower_components/build/js/dist.min.js": [
"bower_components/jquery/dist/jquery.min.js",
"bower_components/angular/angular.min.js",
-> "bower_components/angular-aria/angular-aria.js",
-> "bower_components/angular-animate/angular-animate.js",
-> "bower_components/angular-material/angular-material.js",
"bower_components/angular-mocks/angular-mocks.js",
"bower_components/angular-cookies/angular-cookies.min.js",
"bower_components/angular-resource/angular-resource.min.js",
"bower_components/angular-sanitize/angular-sanitize.min.js",
"bower_components/angular-ui-router/release/angular-ui-router.min.js",
"bower_components/angular-jwt/dist/angular-jwt.min.js",
"bower_components/angular-bootstrap/ui-bootstrap-tpls.js",
"bower_components/angular-ui-select/dist/select.min.js",
"bower_components/web-bootstrap/index.js"
]
}
}
}
I know mean.io says to not alter the core packages, but I didin't find another way to make it work, if anybody has a better solution, please tell us.

.exe doesn't launch after making it with py2exe

So I have been working for 2 months on a project in python (it is the first time I'm using python).
The project is basically:
- 1 main file,
- 1 GUI file using PyQt4
- and a few classes for the calculation functions.
Here is my setup.py file:
from distutils.core import setup
import py2exe
from glob import glob
import matplotlib
dataf = [
(r'mpl-data',
[r'C:\Python27\Lib\site-packages\matplotlib-1.4.3-py2.7-win32.egg\matplotlib\mpl-data\matplotlibrc']),
(r'mpl-data\stylelib',
glob(r'C:\Python27\Lib\site-packages\matplotlib-1.4.3-py2.7-win32.egg\matplotlib\mpl-data\stylelib\*.*')),
(r'mpl-data\images',
glob(r'C:\Python27\Lib\site-packages\matplotlib-1.4.3-py2.7-win32.egg\matplotlib\mpl-data\images\*.*')),
(r'mpl-data\fonts',
glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\fonts\*.*')),
(r'Qt\imageformats',
glob(r'C:\Python27\Lib\site-packages\PyQt4\plugins\imageformats\*.*')),
(r'Resource',
glob(r'C:\PythonWS\Lince5M\*.png')),
]
includes = ['sip', 'PyQt4.QtCore', 'PyQt4.Qt', 'PyQt4.QtGui', 'PyQt4.QtNetwork',]
pack = ['numpy.core', 'matplotlib.backends', 'matplotlib.axes', 'zmq', 'PyQt4.QtCore', 'PyQt4.Qt',
'PyQt4.QtGui', 'PyQt4.QtNetwork', 'CaptureImage', 'ClusterDetectionIterative', 'DisplayPanel',
'ImageProcessAvg', 'WriteOutputFiles',
]
excludes = ['_gtkagg', '_agg2', '_cairo', '_cocoaagg', '_fltkagg', '_gtk', '_gtkcairo', '_thread',
'_macosx',
]
#I admit not understand really much those excludes, that's why I don't put them in the setup
opts={
'py2exe': {
'compressed': 2,
'optimize': 2,
'includes':includes,
'packages':pack,
#'excludes':excludes,
'bundle_files': 1,
}
}
win = [{
'script': 'Application.py',
'icon_resourses': [(1,'icone\icone.png')]
}
]
setup(
version = "0.1",
console=win,
options=opts,
data_files=dataf,
)
My programs works fine when launched with Eclipse.
The making of the executable seems to be done fine too, except for the list of missing modules there is no error, and my .exe is created...
But when I start it nothing happens... I have been looking for a few days now and I really have no idea on what is wrong since nothing gives me a notice on the problem..
If it could be of any use, my project uses those imports:
PyQt4, os, decimal, time, numpy, sys, clr, matplotlib, cv2, and a dll we made in the company.
So here is my question:
Anyone ever got this kind of error?
Does any one know how to get an output, or anything that could tell me where is the problem?
There should be a [.exe name].log file in the "dist" folder that py2exe created.
Try looking to see if that can glean some information on your problem.

Issue with GTK and D

OK, so I'm trying to experiment a bit with D and Gtk.
On OSX, I download the sources and did the typical make, sudo make install.
Now the Gtk sources are installed here :
/usr/local/include/d/gktd-2
However, when I'm trying to build one of the demos included (e.g. /demos/gtk/HelloWorld.d), with :
dmd -I/usr/local/include/d/gktd-2 HelloWorld.d
The compiler still complains :
HelloWorld.d(24): Error: module MainWindow is in file 'gtk/MainWindow.d' which cannot be read
import path[0] = /usr/local/include/d/gktd-2
import path[1] = /usr/share/dmd/src/phobos
import path[2] = /usr/share/dmd/src/druntime/import
What am I missing?
UPDATE :
I think I got it to work, but it's one of those cases where I simply don't know how that happened... lol
To me it seems like a typo - /usr/local/include/d/gktd-2 seems incorrect. It should be something like /usr/local/include/d/gtkd-2 . Following should work: dmd -I/usr/local/include/d/gtkd-2 HelloWorld.d (note the change from "gktd" to "gtkd").

Resources