Transcrypt compilation error Python 3.7 Windows - python

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.

Related

Kicad: error 40 when exporting BOM using Python

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.

How to include pytorch in pyinstaller app?

I am trying to use pyinstaller to "freeze" a python app I've written that uses pytorch. I see that pyinstaller has a hook for torch: https://github.com/pyinstaller/pyinstaller/blob/develop/PyInstaller/hooks/hook-torch.py
But it doesn't appear to work. I still get the following error:
File "torch/_utils_internal.py", line 53, in get_source_lines_and_file
OSError: Can't get source for . TorchScript requires source access in order to carry out
compilation, make sure original .py files are available. Original
error: could not get source code [28326] Failed to execute script
timeslide
I also tried this work-around with no success:
https://github.com/pyinstaller/pyinstaller/issues/2666#issuecomment-370789381
I just need a way to get pytorch to install in a pyinstaller app. It doesn't need to be clean or beautiful. Can anyone suggest a solution?
(macOS and python 3.7)

LD_preload for using other versions of libc, isn't working in pwntools

I want to use other versions of library for my pwn study in pwntools, but EOF error occurred.
I tried to solve this issue , changed ubuntu versions 3 times (18.04 desktop -> 14.04 desktop -> 18.04.0 server), reinstall python and pwntools 4 times.
currently, versions are ubuntu 18.04.0 server, Python 2.7.15rc1, pwntools 3.12.2
I tried using other versions library for my pwn study in pwntools.
like this:
p = process("./binary_name",env={"LD_PRELOAD" : "./libc_name"})
and tried also
env = {"LD_PRELOAD": os.path.join(os.getcwd(), "libc_name")}
p = process("./binary_name",env=env)
and excute python code, Error occurred
I already set the permisson of libc to chmod 777, but result is same.
[*] Process './aeiou' stopped with exit code -4 (SIGILL) (pid 77469)
Traceback (most recent call last):
File "ex4.py", line 6, in <module>
p.sendlineafter(">>","3")
File "/home/synod2/.local/lib/python2.7/site- packages/pwnlib/tubes/tube.py", line 747, in sendlineafter
~~~~~~~~~~~~~~
EOFError
I dont know why EOF error occurred. but, because of 3 differents version ubuntu give the same error, I think I missed install something.
but I don't know what I missed!
Maybe you should try it on Ubuntu 16.
Obviously your binary file is dynamic linked. So when the program need to call some libc function such as read. It will pass some information to the dynamic linker, then the linker will calculate the real address of the read function.
but functions in libc has a version attribute. So if you try to use LD_PRELOAD on Ubuntu 18.04. the dynamic linker would try to find sth like read_2_27 in you 2.23-version-libc which only have read_2_23. so your program would fail to execute.
UPDATE:
another solution is to tell the excutable file to use the correct version of ld.so
elf file has a segment(INTERP) in which save the path to the ld.so to use. you can just change it to the path to ld.so you want to use.
BTW, you can find many version of ld.so in the repository

Error when converting C code to Web Assembly

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

Using msi.py to install Python3.4

So I downloaded source for Python3.4 and used VisualStudio 2010 to build a Python executable for my Windows7 machine. Ultimately, I want to use this to embed Python support in my application.
The first time I tried to execute my app, PyInitialise ends up aborting, and presents the error message:
"Py_Initialize: unable to load the file system codec"
So now I'm thinking, D'oh, you never installed your Python build after building it. After much googling, I find myself running msi.py. When I do, I see:
File "msi.py", line 934
raise ValueError, "Could not find "+srcdir+"/../"+pat
^
SyntaxError: invalid syntax
This looks to me like I'm trying to run pre-Python3.X code. But I'm so sure this MSI tool came with my Python3.4 source distribution. That said, I've been staring at this for so long things are starting to blend to a blur.
Any clues about where to look or what to try next?
Should I be worrying about MSI? Is there some other answer to my codec problem?

Categories