How to fix ‘--go_out: protoc-gen-go: The system cannot find the file specified.’ error - windows

I Create a person.proto and I wanna compile this file to *.go .
I installed Package
go get -u github.com/golang/protobuf/protoc-gen-go
After executing the following command
.\protoc.exe --go_out=. person.proto
I get the error below
--go_out: protoc-gen-go: The system cannot find the file specified.
I want to use the buffer protocol, version 2
How can I fix this error?
My proto file:
package communication;
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
}

Description
Unfortunately, it is said that none of the core developers develop on Windows, hence I solve the problem and add this answer for Windows developers.
However, the possible duplicate link that #Flimzy mentioned doesn't work and I have done all the 6 steps below then surprisingly the problem has solved by step 7. Moreover, by mistake, I was running the command on a VSCode terminal.
Procedure
Download protoc-win32.zip from "https://developers.google.com/protocol-buffers/docs/downloads".
Unzip the file then add the location of the protoc.exe to your PATH environment variable. In addition, it's not that much necessary, you can copy the protoc.exe to the GOPATH.
Change/Navigate the CMD/Powershell path to the file then run protoc.exe --version from the command prompt to verify the procedure.
Verify that your GOPATH environment variable is set.
Run go get -u github.com/golang/protobuf/protoc-gen-go from the CMD/Powershell. This should install the binary to %GOPATH%/bin.
Add the exact %GOPATH%/bin to your PATH environment variable.
Open a new CMD/Powershell, navigate to your .proto file then run protoc --go_out=. *.proto
References:
How to install protoc-gen-go (Go protocol buffer compiler plugin) in windows?
protoc-gen-go: protoc fails to compile in Windows

On windows, I ran the following command to resolve the issue.
go install google.golang.org/protobuf/cmd/protoc-gen-go#latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc#latest
go-zero
Google developer

Related

Failure: plugin grpc-gateway: could not find protoc plugin for name grpc-gateway -

while genrating Prot buff using "buf generate"
i am getting below error :
Failure: plugin grpc-gateway: could not find protoc plugin for name grpc-gateway - please make sure protoc-gen-grpc-gateway is installed and present on your $PATH
i have tried installtion of
"go install google.golang.org/grpc/cmd/protoc-gen-go-grpc#latest; "
$ go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway#latest
$ go install google.golang.org/protobuf/cmd/protoc-gen-go#latest
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc#latest
then check for your path , if its not set then use below command :
PATH="${PATH}:${HOME}/go/bin"
The error is specifically for protoc-genc-grpc-gateway which is distinct from proto-gen-go-grpc.
See the Installation instructions that include protoc-gen-grpc-gateway.
You will also need that the plugin is in your host's PATH. On Linux you can which protoc-gen-grpc-gateway to confirm this after installation.

Download go modules Nix OS

I'm downloading a program from github and trying to build it. The program is written in go and uses external modules. After running the nix script, I get an error suggesting that I use the go get command. How can I get modules from a nix script?
My nix script:
buildGoModule rec{
name = "HH";
src = fetchGit{
url = "git#github.com:q/q.git";
};
vendorSha256 = "";
}
Error:
hh imports
github.com/google/uuid: no required module provides package github.com/google/uuid; to add it:
go get github.com/google/uuid

Protobuf timestamp not found

Relatively new to GRPC and getting an error in my proto file that I cannot seem to make sense of. I would like to send a time in a message using the "google.protobuf.Timestamp". I cannot seem to import it. What am I doing wrong?
syntax = "proto3";
import "google/protobuf/timestamp.proto";
service ProfileService {
rpc ConstructProfileStructFromUser (ConstructProfileStructFromUserRequest) returns (ConstructProfileStructFromUserResponse);
}
message ConstructProfileStructFromUserRequest {
string transactionID = 1;
string User = 2;
}
message ConstructProfileStructFromUserResponse {
string UID = 1;
string ContactEmail = 2;
google.protobuf.Timestamp DateOfBirth = 3;
}
Both in my IDE and my compiler (using the below command) then I get the error
google/protobuf/timestamp.proto: File not found.
profile.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
profile.proto:21:5: "google.protobuf.Timestamp" is not defined.
Command to run:
protoc -I profile/ profile/profile.proto --go_out=plugins=grpc:profile
Protoc --version
libprotoc 3.0.0
I had this issue after installing the protoc compiler using the apt package manager (Ubuntu) and it put the protoc compiler somewhere like /usr/local/bin.
It seems by default protoc expects imports to be present in an include path relative to the protoc installation directory. For example:
protoc location: /usr/local/bin/protoc
include location: /usr/local/bin/include/*
Install pre-compiled binaries (any OS)
Downloading a pre-compiled binary as indicated below will have the needed include directory.
Instructions from grpc.io/docs/protoc-installation
Manually download from github.com/google/protobuf/releases the zip file corresponding to your operating system and computer architecture (protoc--.zip), or fetch the file using commands such as the following:
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip
Unzip the file under $HOME/.local or a directory of your choice. For example:
unzip protoc-3.15.8-linux-x86_64.zip -d $HOME/.local
Update your environment’s path variable to include the path to the protoc executable. For example:
export PATH="$PATH:$HOME/.local/bin"
If you installed protoc with your package manager, you only have to install the libprotobuf-dev (Ubuntu) or protobuf-devel (Fedora) package.
In general, you can find the containing package of a file on Ubuntu with
apt-file find google/protobuf/timestamp.proto
or on Fedora
dnf repoquery --file "**/google/protobuf/timestamp.proto" (this is how I found the package I needed). Other package managers probably have similar commands.
My problem was quite simple...
I didn't have the timestamp.proto downloaded locally and as a result it couldn't find it.
I cloned:
https://github.com/protocolbuffers/protobuf/tree/master/src/google/protobuf
And then when I run my compiler I have to give it the location to locate the timestamp.proto files.
For me it was...
protoc -I profile/ -I MY_CLONED_REPO_LOCATION/protobuf/src profile/profile.proto --go_out=plugins=grpc:profile
Once it knew where it had the path to the source then it could find it with no issues.
I had same problem with protoc 3.0.0 installed from ubuntu repo. I have found another solution, without reinstalling protobuf as #SwiftD suggested, using --proto_path protoc option.
In your .proto import should look like (i.e. without path):
syntax = "proto3";
import "timestamp.proto"
Then in the protoc invocation you pass absolute path to your package directory containing timestamp.proto (I use github.com/golang/protobuf/ptypes/timestamp) using --proto_path option.
protoc kcproto.proto --go_out=./ --proto_path=/home/my_home_dir_name/go/src/github.com/golang/protobuf/ptypes/timestamp --proto_path=./
replace /home/my_home_dir_name/ with your go package directory
For mac, I run this in the terminal
PROTOC_ZIP=protoc-3.14.0-osx-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP
Note that you can change the version protoc-3.14.0 to whatever your need, for example protoc-3.x.x
Docs: http://google.github.io/proto-lens/installing-protoc.html
If you download from https://github.com/protocolbuffers/protobuf/releases, in the download directory there is an include directory, where all the google defined types (such as google/protobuf/timestamp.proto) live.
You can pass in an extra parameter --proto_path=/path/to/include to your protoc command, and it should work.
Go to the VSCode proto 3 extension settings and paste "protocol" at the end of the file:
"protoc": {
"options": [
"--proto_path=proto",
]
}
}
I had the same problem with
import "google/protobuf/timestamp.proto";
I'm on a fedora and installed protocol buffer compiler using the package manager dnf .
solution : delete your current protoc using then package manger .
on fedora:
sudo dnf remove protobuf-compiler
then follow the instruction to Install pre-compiled binaries (any OS) :
find the appropriate version of compiler herer https://github.com/protocolbuffers/protobuf/releases
unzip it in somewhere in your PATH . for example you can do something like this : $ unzip protoc-3.15.8-linux-x86_64.zip -d $HOME/.local
DONE !
What I ended up doing in same situation was to include
message google {
message protobuf {
message Timestamp {
int64 seconds = 1;
int32 nanos = 2;
}
}
}
In my proto-file. That was enough for it to be recognized as well known type, so in python I get the addition API described at https://developers.google.com/protocol-buffers/docs/reference/python-generated#timestamp.
The main advantage is that we all can keep using the system install of protoc and don't have to install from source.

Build R source code from windows

C:\Work\R contains the R-3.1.1.tar.gz file
I have build R source(R-3.1.1) in windows 8 from the following commands
cd C:\Work\R
tar --no-same-owner -xf R-3.1.1.tar.gz
cd C:\Work\R\R-3.1.1\src\gnuwin32\
make all recommended
Add the following path to the Environment variables
C:\Work\R\R-3.1.1\bin\i386
Enter the R.exe in command promt
I got the following Error
Fatal error unable to open the base package
System information
Windows 8, 64 bit operating System, x64 –based processor
How to resolve this error?
If you are using R, you can download the newest version from here and then simply install it.
If you have an older version and want only to download the new one, use those commands inside R:
# installing/loading the package:
if(!require(installr)) {
install.packages("installr"); require(installr)} #load / install+load installr
# using the package:
updateR() # this will start the updating process of your R installation. It will check for newer versions, and if one is available, will guide you through the decisions you'd need to make.
We can resolve this issue by using the following command before build the R source code
Set TMPDIR=c:\cygwin64\bin
Here c:\cygwin64\bin is the cygwin installed location in Windows 8 machine.
Here I have mentioned the R source code build steps:
Install cygwin setup
Install RTools
Create the R_HOME file in the directory like C:\R_HOME
Place the R source code tar file in the R_HOME
Add the following path in environment variable in first
c:\Rtools\bin\;c:\Rtools\gcc-4.6.3\bin;C:\cygwin64\bin\;C:\Program Files (x86)\HTML Help Workshop\;C:\R_HOME\R-3.1.1\bin\;
Enter the following command in the command prompt
Set TMPDIR=C:\cygwin64\bin
Set working directory as C:\R_HOME
Enter the following command
tar --no-same-owner -xf R-3.1.1.tar.gz
Copy the Tcl source from c:\R (it will be created while installing RTools)
Set the working directory as follow in command prompt
C:\R_HOME\R-3.1.1\src\gnuwin32
Enter the following command
Make all recommended
Enter the R.exe command in command prompt. We can enter the R terminal

Error in installing a modified package from local modifed zip file

I found a small bug in a R package. I communicated with the package author to update the code. While waiting for the author action to fix the bug, I am trying to fix the bug on my local version of the package.
I changed the R code, and also updated the MD5 of the associated file. The package is re-zipped, and I use this command to install it:
install.packages("path/to/the/file/modified_package.zip", repos = NULL)
it seems the installation is going well:
Installing package(s) into ‘C:/Users/Me/Documents/R/win-library/2.15’
(as ‘lib’ is unspecified)
package ‘x’ successfully unpacked and MD5 sums checked
However, when I try to load the package, there is an error:
> library(x)
Error in library(x) : ‘x’ is not a valid installed package
Any thoughts?
You can't just zip up the directories; you need to rebuild the package.
There are loads of guides around on how to build R packages. The easiest way (imho) is to use the devtools package.
library(devtools)
build("path/to/the/package")
install.packages("path/to/built/package.tar.gz", repos = NULL, type = "source")
Or
build("path/to/the/package", binary = TRUE)
install.packages("path/to/built/package.zip", repos = NULL, type = "win.binary")
You'll also need Rtools if you are running Windows. Install it with the installr package.
library(installr)
install.Rtools()

Resources