I have successfully installed Emscripten and have it running on an Ubuntu 16.04 virtual machine. I have also successfully converted a helloworld.c file to web assembly. Currently, I am attempting to convert python to web assembly with emscripten. The issue is that emscripten does not support python currently, so as a work around I have attempted to convert the python code to C with Cython, which I successfully did. Though I am getting an error when attempting to convert the cython c file to Web assembly. Here is the console log:
$emcc pony_gp.c -o pony_gp.html
In file included from pony_gp.c:11:
In file included from /usr/include/python2.7/Python.h:58:
/usr/include/python2.7/pyport.h:886:2: error: "LONG_BIT definition appears
wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting
According to pyport.h, this error is generated because in some 32 bit systems LONG_BIT is defined incorrectly as 64 when it should be 32. I have tried commenting out this line, but this only allowed the program to silently run, in the end without producing any web assembly code, only html and javascript.
I have read here, that the issue is because "cmake is picking up one version of the python dylib and a separate version of python for the headers". This makes sense as I recently downgraded from Python 2.7.13-1 to Python 2.7.11-1 because Python 2.7.13-1 was not compatible with python-dev packages. Though, I don't know how I would fix this.
Does anyone have an idea on what to do?
While not a full answer, you should be able to compile pony_gp.c directly to LLVM (.ll) using clang, preferably the same clang provided with Emscripten, for example:
source ~/emsdk/emsdk_env.sh
cython hello.py
clang `python2-config --cflags` -S -emit-llvm hello.c
Then, the generated .ll file could be fed directly to Emscripten.
For producing a fully working Python -> WebAssembly you should probably also need to link against the Python runtime - you could use the one distributed with emcc which is already compiled into LLVM bytecode (.bc), emsdk/emscripten/incoming/tests/python/python.bc.
Also, this may be of help: https://github.com/dgym/cpython-emscripten
Related
From EESchema I’m trying the various BOM export scripts to find which one is better for my needs. Most of them fails with the following error, though:
Run command:
python "/usr/share/kicad/plugins/bom_html_with_advanced_grouping.py" "/home/andrea/myboard.xml" "/home/andrea/myboard"
Command error. Return code -1
Error messages:
execvp(python, /usr/share/kicad/plugins/bom_html_with_advanced_grouping.py, /home/andrea/myboard.xml, /home/andrea/myboard) failed with error 40!
I cannot understand what is "error 40".
Here the list of the scripts that fail:
bom_html_with_advanced_grouping.py
bom_html_grouped_by_value.py
bom_sorted_by_ref.py
bom_csv_sorted_by_ref.py
bom_csv_grouped_by_value_with_fp
bom_csv_grouped_by_value.py
They all seem to use Python, so I guess there's something wrong with it. But in my system I have a working python2 and python3 and I also checked the built-in Kicad's python is working (i.e. from Pcbnew I can successfully open Tools > Scripting Console). So I don't think this is the problem (otherwise Kicad would have told if it hadn't found the needed dependencies).
I also tried to create alias for python to python2 or python3 but nothing has changed.
Furthermore I don't understand if "Error 40" comes from Kicad, Python or execvp.
Kicad information:
Application: Eeschema
Version: 5.1.9-73d0e3b20d~88~ubuntu20.04.1, release build
Libraries:
wxWidgets 3.0.4
libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
Platform: Linux 5.4.0-65-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24
Boost: 1.71.0
OpenCASCADE Community Edition: 6.9.1
Curl: 7.68.0
Compiler: GCC 9.3.0 with C++ ABI 1013
Build settings:
USE_WX_GRAPHICS_CONTEXT=OFF
USE_WX_OVERLAY=ON
KICAD_SCRIPTING=ON
KICAD_SCRIPTING_MODULES=ON
KICAD_SCRIPTING_PYTHON3=ON
KICAD_SCRIPTING_WXPYTHON=ON
KICAD_SCRIPTING_WXPYTHON_PHOENIX=ON
KICAD_SCRIPTING_ACTION_MENU=ON
BUILD_GITHUB_PLUGIN=ON
KICAD_USE_OCE=ON
KICAD_USE_OCC=OFF
KICAD_SPICE=ON
If you are not sure about a BOM script, to get diagnostics you can run them from the command line. There is nothing special about the way KiCad invokes them.
I just tried the latest transcrypt on Python 3.7 Win7 with the simple program from https://github.com/bunkahle/Transcrypt-Examples/blob/master/alerts/alerts2.py but I got an compilation error:
C:\Python37\Programme\Transcrypt>transcrypt alerts2.py
Transcrypt (TM) Python to JavaScript Small Sane Subset Transpiler Version 3.7.16
Copyright (C) Geatec Engineering. License: Apache 2.0
Saving target code in: C:/Python37/Programme/Transcrypt/__target__/org.transcrypt.__runtime__.js
Saving minified target code in: C:/Python37/Programme/Transcrypt/__target__/org.transcrypt.__runtime__.js
Error while compiling (offending file last):
File 'org.transcrypt.__runtime__', line 0, namely:
[WinError 2] The system cannot find the specified file
Aborted
Any idea what went wrong? I just get a directory named __target__
which holds one file called org.transcrypt.__runtime__.pretty.js but no alerts2.js whatsoever. BTW why did you change the __javascript__ name of the compilation directory from transcrypt 3.6 to __target__ in transcrypt 3.7?
OK, I finally found out myself what went wrong. In case you get that error most probably Java is not installed on your machine which is needed to minify the javascript code which transcrypt seems to try by default. So just invoke the command:
transcrypt -n alerts2.py
and it runs without any error because -n disables minification of the code. BTW it would be nice if transcrypt would output an error message like "Warning: No Java installed - minification is disabled. Install Java for code minification." or the like and still output the not minified code. Or even better not rely on Java at all for code minification. Should be a three liner in Python I think.
I'd like to use cjson in Maya 2018 but I'm running into some trouble. The original tool seems to be 32-bit compiled (https://pypi.org/project/python-cjson/) so I looked around and found a version that was compiled in 64-bit from https://www.lfd.uci.edu/~gohlke/pythonlibs/.
Using "C:\Program Files\Autodesk\Maya2018\Python\Scripts\pip.exe" in admin mode I managed to pip install the 64-bit wheel file and that's given me cjson.pyd in my Maya 2018 site-packages directory.
However, when I try to import this I get the error:
// Error: root : [('<maya console>', 2, '<module>', None)] //
// Error: root : DLL load failed: The specified module could not be found. //
// Error: //
Has anyone had any experience importing this module into Maya before?
I have a feeling this could be to do DLL dependencies but I'm not sure where to begin solving it.
So, traditionally you'd check your dll for dependencies using something like Dependency Walker. .pyd files are just renamed .dll files, so should work fine with this. However, Dependency Walker is mostly full of noise - unless you spot something really obvious (and you can ignore all the API-MS-WIN*, EXT-MS-* dlls straight away) then you might find it easier to enable Loader Snaps (see this old but still relevant MSDN article) which should hopefully be able to tell you which loadlibrary call is failing. Alternatively, you can use Process Monitor (procmon) form Sysinternals to see what files Maya attempts to load when you import the module in to a script. I can't remember if Maya spawns a separate process to run it's python scripts in, or if they're executed in the context of the main maya process. This is important as you'll want to filter events in procmon to just maya / the python executable as otherwise you'll be swamped by them.
Edit: Having looked through the source code there doesn't appear to be much in the way of dependencies beyond the python headers themselves and some standard library includes. I suspect it's more likely that this is compiled with a different version of the toolchain than Maya's Python. In the Python interpreter, you should see a line like this when you start it:
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
It would be good to see what toolchain was used to compile it (the square brackets bit), and then build the extension from source again with that toolchain. Alternatively, you can try running the setup.py for this module from the project's GitHub page, which if your machine is set up to be able to compile python extensions correctly will build it from source. More details about building c extensions can be found on the Python docs page.
I want to add python functions in C++ code.
I made a GUI in gtk (on the Raspberry PI) and now I want to work with a camera module which is easy to handle in python. (I want to start a video directly when I push a button.)
So I included the file Python.h
#include <python3.4m/Python.h>
#include <python3.4m/pythonrun.h>
then I thought it should work, but when I try to compile Py_Initialize()
I get the error:
undefined reference to Py_Initialize.
I think this is strange because, when I type in, there came the selection for Py_Initialize.
In terms of headers you should be fine, since it compiled but failed at linking.
Now you need to link against the Python libraries. The way this is done largely depends on what toolchain you are using.
Maybe you can see my answer in another question:
if with python 3.x installed, maybe this command can work:
g++ hw.cpp `/usr/bin/python3-config --cflags` `/usr/python3-config --ldflags`
By the way, you should check you gcc and python version.
As I know, if gcc version is 5.4 and python version is 3.7, it doesn't work.(python 3.5 >is work)
When you run /usr/bin/python3-config --cflags, in fact, it is the compile option.
Set the python include folder and it static lib on gcc command line and put the python dynamic lib on LD_LIBRARY_PATH. Before Py_Initialize(), do not forget to set python home with Py_SetPythonHome(). These steps must be sufficient for your code compile and run.
I am running some python code where some code needs gcc compilation (dont ask me I dont have a clue). I was getting the error that gcc not recognised. I installed Mingw and gcc compiler, so that was sorted. But now the assembler is creating a very large file name and getting into error. see the error below:
Assembler messages:
Fatal error: can't create c:\users\kd1234\appdata\local\temp\scipy-as07487-7op0cx\python27_intermediate\compiler_6cb9c52cab22cd58c3b2a33f029b68476828f4189dc8dd305efd20ec06666d43\Release\users\as07487\appdata\local\temp\kd1234\python27_compiled\sc_ed5391b748bc47781f90305835197df10c5f33c0bbba9a3f5660ab3c277c2b50657.o: No such file or directory
I looked at it and it looks like this file name generated by the compiler is too large for windows thus cant create it and getting into error.Has anyone got some idea how to sort this one out!
Cheers
That path length is 290 characters, which does indeed exceed the limit of 260 characters imposed by most Windows APIs.
Part of the path bloat appears to be due to %TEMP%; try setting %TEMP% to C:\ before running the script and see if that makes it work.