How to run a protobuf python plugin on Windows - python

I'm currently using a Protobuf plugin to generate some custom C# code given a set of Protobuf files. It is running fine on Linux and I would like to run it on Windows as well in order to generate this code directly from my Visual Studio project.
Here is the command line I am (unsuccessfully) using currently :
path\to\protoc.exe --plugin=protoc-gen-my-plugin=path\to\my-plugin.py --my-plugin_out=output\path\gen my_proto.proto
And here is the error I'm getting :
--my-plugin_out: protoc-gen-my-plugin: %1 n'est pas une application Win32 valide.
I have Python 2.7.11 installed and it is in my path. I also tried to run protoc.exe using both x86 and x64 executables.
Is there any limitation I'm not aware of or did I miss something?

I was able to fix my issue by encapsulating the python plugin in a .bat file. Here is the code I used :
#echo off
chdir path\to\my-plugin
python -u my-plugin.py
The "-u" option when running the python script is really important because otherwise the standard input will be buffered. As protoc is passing all the inputs to the plugin (the .proto files to parse) through stdin this is really important. And the output is written by the plugin to stdout, so no issue there.
Here is the final command to execute protoc with my plugin :
path\to\protoc.exe --plugin=protoc-gen-my-plugin=redirect.bat --my-plugin_out=output\path\gen my_proto.proto

Related

Python in Visual Studio Code without PowerShell

So I need to use Python for my work. Unfortunately, since recent hacks, the companies security policies are very strict and there is no way I'm getting admin rights. I managed to persuade our IT to install Python, Visual Studio Code, and the Python extension for it on my computer.
If I try to run python commands in the Python interpreter it works. But when I try to run a Python script in Visual Studio Code it hast to run Power Shell which is also blocked for security reasons.
I get the following error:
The terminal process command 'C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe' failed to launch (exit code: {2})
Is there some way around this? To use Python in Visual Studio Code despite all of the security restrictions?
I tried asking our IT department but they have no idea how to help me...
Thank you in advance.
You can change the VS Code settings and tell it to not use PowerShell as shell in the integrated terminal.
For example, I have put Windows Terminal in there, but you can also use CMD or any other shell such a git bash as long as it's available in your system.
Press ctrl+shift+p and type/select Open Settings (JSON). Then add some of the following to this configuration file, and save.
For Windows Terminal:
"terminal.external.windowsExec": "C:\\Users\\<your-username>\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"
For CMD:
"terminal.external.windowsExec": "C:\\Windows\\system32\\cmd.exe"
I'm used below code in setting file and it works.
"terminal.integrated.defaultProfile.windows": "Command Prompt"

Why doesn't Visual Studio Code recognize my WSL bash python?

I am running Visual Studio Code on Windows 10 with WSL bash as its terminal:
"terminal.integrated.shell.windows": "C:/Windows/sysnative/bash.exe"
In WSL bash I have both python (v2.7) and python3 (v3.6) installed.
I have installed the Python extension for VS Code. Unfortunately VS Code fails to recognize either version of Python in WSL bash.
For example when I try to discover tests, I get the following error in the Python Test Log output window:
Test Discovery failed:
Error: spawn python ENOENT
How can I configure VS Code to work with Python form WSL bash?
Note: I'm pretty sure I need to configure a path to Python in the "python.pythonPath" key in VS Code's user settings file. I am unsure of which path to put as the value though.
Support for WSL is done through the "WSL - Remote" extension. There is a WSL blog post which covers how to get started.

How to read a chm file from a python code running on windows

I want to know some uses of pychm package :
Is this package useful only on linux
Would it ever be useful for a python program runnning on windows
So if I am writing a python script on windows and if this script must extract information from a chm file, then how do I do it.
I am also trying to install the python chm package on windows to have a better understanding. But When I execute pip install pychm I get the following error :
chm/swig_chm.c(681) : fatal error C1083: Cannot open include file: 'chm_lib.h': No such file or directory
Can someone explain me all these issues. It might be a very trivial query but has been troubling me for quite some time

Getting GDB pretty printing for C++ stl containers to work on Eclipse

gdb shows the following when I type "show version":
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5_5.2)
I followed the instructions on this website for setting up pretty printing with Eclipse:
http://wiki.eclipse.org/CDT/User/FAQ#How_can_I_inspect_the_contents_of_STL_containers.3F
When I attempt to start gdb with my new .gdbinit file, I get the following error:
Error in sourced command file:
Python scripting is not supported in this copy of GDB
So then I researched around for a way to enable this. I have over version 7.0 so it should be able to support Python scripting. GDB's website mentions calling the GDB configure script with the --with-python option. However, I don't see a configure script anywhere in my system. There are multiple developers using this machine so I don't want to have to reinstall GDB or anything like that. Is there a way to configure the existing GDB installation to enable python scripting? Thanks!
To get you started, you can compile GDB in a separate directory, and run it from there.
Grab the sources for the version you want:
http://sources.redhat.com/gdb/
Run ./configure with the --with-python, and then make, but don't install it over your system copy.
At that point, you should be able to invoke gdb where it has been built with ./builddir/gdb, rather than the one in your path. (This is where you should point eclipse debugging to, if you want to invoke it from there)

Python 3.2 doesn't work with python 2.7

I already have python 2.7 (installed using activepython). I'm trying to use python 3.2 just to learn more about it so i downloaded it from python.org
python 2.7 still works perfectly, but python 3.2 gives me this error when i try to open the ide.
and then I see the send error window, if i install python 3.2 using activepython i see the same error.
I'm using windows xp pro sp3 32 bit and i had the same error on sp2... How do I fix it?
EDIT #Zuljin
This is the first time that i use dependancy walker so could you give me a hand please
this is what i see
what does that mean? I already have these files...
I saw a lot of answers here. But, I think the file that you are trying to run is not correct
C:\Python32\Pythonw.exe
is not the one you use to open idle.
Open
C:\Python32\Lib\idlelib\idle.pyw
Python 2.x and 3.x can cohabitate perfectly in win xp and win 7, either 32 or 64 bits.
If you first installed the ActiveState Python distribution, be careful when installing python-3.2.2.msi.
When you arrive to the customize python 3.2.2 screen, (un)check 'register extensions' to make the feature unavailable (that is: do not register extensions).
I have installed this way both distributions in different computers without any problem so far.
Note: Check your environment variables. Only python 2.7 should be in the path (if you installed before the two distros you could have them both in the path. Remove python 3.2 path)
Edit:
From Ankit post I realized that in fact you were trying to open IDLE, maybe.
If you follow my installation instructions when you call idle.bat from the py3.2 idlelib folder you actually get idle for python 2.7 as this is what the call find in the windows path. To be able to open idle for py3.2 in the presence of python 2.7 as the registered python, I use a .bat file modified from that in the distribution:
idle_stay.bat
#echo off
rem Working IDLE bat for Windows - Custom bat for py3k as secundary python
C:\Python32\pythonw C:\Python32\Lib\idlelib\idle.pyw %1 %2 %3 %4 %5 %6 %7 %8 %9
The name idle_stay.bat is because I put this file in the folder where the official idle.bat is (C:\Python32\Lib\idlelib\idle_stay.bat). In this way it does not get overwritten each time I unisntall and reinstall a new version of python 3
It seems to me you have associated a *.py or *.pyw file extension type to some version of python.exe and/or pythonw.exe you aren't clear about. This is often, but not exclusively done from within Microsoft's "explore.exe" File Manager (I believe in Options).
I disagree that this is a reliable method:
C:\Python32\Lib\idlelib\idle.pyw
as this method will run whichever program is assigned to the "pyw" extension. That could be:
C:\Python32\pythonw.exe
or
C:\Python26\python.exe
or whatever might have happened to your file extension association as per OS or bad PATH environment variable setting. It is better to do something like this:
C:\Python32\pythonw.exe C:\Python32\Lib\idlelib\idle.pyw
where you are explicidly telling the OS to run the python executable from a specific path and selecting a specific python script in the file/folder hiearchy.
Another thing you can try to gather info is just:
python.exe -V
which will tell you the version number.
Another thing you can do:
Open a DOS command prompt and type:
set PATH=C:\Windows;C:\Windows\system32;C:\Python32
python.exe and note the version and whether is runs.
exit()
exit
Once working debug your PATH. You can use this Python script to gather intel.
If you turned off your WinXP findfile stuff (like I have) you can use this script:
inpath.py can help shed some light.
Run this python script like this:
Drop to a DOS prompt
cd to your folder with a working python.exe version.
and type python.exe inpath.py python*
where inpath is in that same folder for this test/debug.
inpath.py will search your path for all files associated as "runable" in your OS and that is in your "PATH" with the python*.* pattern.

Categories

Resources