Where to set the path to the protoc to import standards Protocol Buffers - dart

Where need I to set the path to the protoc to get import standards Protocol Buffers (protobuf), like empty.proto and timestamp.proto in Windows and Dart?
When the protoc is ran:
protoc --dart_out=grpc:lib/src/protos/generated -Iprotos
protos/organization.proto
--plugin=protoc-gen-dart=D:\Users\Samuel\AppData\Roaming\Pub\Cache\bin\protoc-gen-dart.bat
The following error is presented:
google/protobuf/empty.proto: File not found. organization.proto:
Import "google/protobuf/empty.proto" was not found or had errors.
organization.proto:14:27: "google.protobuf.Empty" is not defined.
In IntelliJ Settings on Protobuf Support plugin the path is define where standard protos (*.proto) are:
Additionally this path is define in IntelliJ on Project Structure \ Global Libraries:
The code organization.proto that import google/protobuf/empty.proto to use Empty class :
syntax = "proto3";
package auge.protobuf;
import "google/protobuf/empty.proto";
service OrganizationService {
rpc GetOrganizations (google.protobuf.Empty) returns (OrganizationsResponse) {}
}
IntelliJ analyzer recognizes the import "google/protobuf/empty.proto" and Empty class on IDEA, but protoc can not find.
The environment is:
SO: Windows 7 x64
protoc: libprotoc 3.6.1
Dart: 2.2.0-edge

Say you have /some/path/to/google/protobuf/empty.proto, you need to pass --proto_path=/some/path/to/ so protoc can locate it.

use two dot before protobuf folder path
<Protobuf Include="..\Proto\protobuf.proto" ProtoRoot="Proto" />

Related

Could not find module ‘Text.Megaparsec.Char.Lexer’

I tried "stack install megaparsec", adding megaparsec and parsec as a dependency in the project.yaml file and running stack build, i tried stack build on all levels of the project folder. Also what's weird is that I can load the module which contains the imports which are marked as problems by VSCode and show the error message and I can also run the functions in said module which make us of the imported stuff but I can't compile the file.
ghci version is 9.0.1
stack version is 2.7.3
cabal-version: 1.12
Error message from terminal
module Parsing where
import Control.Monad (void)
import Data.Void
import Syntax
import Data.Text (Text)
vvvvv these 3 are marked as problems and are the reason I can't compile the file.
import Text.Megaparsec
import Text.Megaparsec.Char
import qualified Text.Megaparsec.Char.Lexer as L
.cabal file
library
exposed-modules:
Example
Lib
Parsing
Print
Semantics
Syntax
other-modules:
Paths_parser
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
, containers
, megaparsec
, parsec
, text
default-language: Haskell2010
executable parser-exe
main-is: Main.hs
other-modules:
Paths_parser
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, parser
default-language: Haskell2010
test-suite parser-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_parser
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, parser
default-language: Haskell2010

Run dart script outside of a project folder

I am trying to replace python with dart as a scripting language for my tools. I can create a python file anywhere, import global packages and run it but I can't seem to get this working with dart. Do I always need a pubspec.yaml file to run a dart script?
This is the script I am trying to run:
import 'package:http/http.dart' as http;
main(List<String> args) async{
var res = await http.get('https://example.com');
print(res.headers);
}
This is the error I am getting:
Error: Could not resolve the package 'http' in 'package:http/http.dart'.
test2.dart:1:8: Error: Not found: 'package:http/http.dart'
import 'package:http/http.dart' as http;
^
test2.dart:4:19: Error: Method not found: 'get'.
var res = await http.get('https://example.com');
No, you don't need a pubspec.yaml file to run a program, but it does need to somehow be able to resolve all the imports.
The pubspec.yaml file is used for obtaining the packages (from pub.dev, a git repository, etc.) but not for finding the packages at runtime. The pub program reads the pubspec.yaml file and downloads the packages mentioned in it, and maintains a packages specification file indicating where each package resolves to. By default the packages specification is in a file called .packages in the same directory as the pubspec.yaml file. The Dart runtime normally finds the packages by looking at the .packages package specification file, but there are other ways.
Here are some options:
Put a .packages file in the same directory as the Dart program, or in an ancestor directory.
Use the --packages option to specify the package specification file to use:
dart --packages=/home/username/stuff/mypackagespecfile myprogram.dart
The Dart runtime also has a --package-root option. But I haven't figured out how to make it work.
The import statements use URIs, so import 'file://...'; can also work in some cases.
Use dart2native to compile the program into an executable.
Note: Dart scripts can also start with a hash-bang line:
#!/usr/bin/env dart
import 'package:http/http.dart' as http;
main(List<String> args) async{
var res = await http.get('https://example.com');
print(res.headers);
}
Then you can make the program executable and run it without needing to type in the Dart runtime:
$ chmod a+x myprogram.dart
$ ./myprogram.dart

How to fix find error for dart:html in VSCode?

I try to run in VSCode a simple dart program with
import 'dart:html';
clause.
import 'dart:html';
// import 'package:html/dom.dart';
// import 'package:html/dom_parsing.dart';
// import 'package:html/parser.dart';
void main() async{
var myTable = new TableElement()
..setAttribute('border','1');
// ..setAttribute(name, value);
...
In Run mode (I use VSCode extension "Code Runner 0.9.9") and in Debug appeared the same error:
Error: Not found: 'dart:html'
import 'dart:html';
I have installed Dart SDK 2.3.1 at Windows10 and not installed Flutter at all.
PATH pointed to Dart SDK bin directory
PATH =D:\Dart\dart-sdk\bin;
*) At project directory I try to add additional directive at pubspec.yaml
dependencies:
----
name: main
description: Test App sample22
dependencies:
html:
---
After "pub get" command I'll see that html present but error still persist.
pub get
Resolving dependencies...
+ charcode 1.1.2
+ csslib 0.16.0
+ html 0.14.0+2
+ path 1.6.2
+ source_span 1.5.5
+ term_glyph 1.1.0
Changed 6 dependencies!
*) My next step was to import html parts via "package:html/" (marked as comments in code sample). It is not helped and required class TableElement still unrecognizable.
"main.dart:8:19: Error: Method not found: 'TableElement'."
*) I try to change "launch.json" string from
default
"program": "bin/main.dart",
to
"program": "D:/Dart/WRK03t/main.dart",
And rename my code file to "main.dart"
*) Also I try to remove Dart extension from VSCode, restart PC and install it again. it's not helped.
But let me say that when I compile main.dart to js
"dart2js -m -o tst.js main.dart"
Resulted tst.js run correctly within the html page.
Almost the same problem in Request Dart Installation doesnt find dart:html
dart:html is only available in the browser. This is the error you get if you try to run code that uses it on the VM (instead of the browser). This is expected.
If you need to run your code outside of the browser (eg. in the VM as a CLI app or via Fluter) you cannot use dart:html. If you only want to use it in the browser but VS Code is trying to run your code in the VM, you'll need to set up some VS Code tasks/launch configs to run build_runner, similar to the Dart DevTools project:
https://github.com/flutter/devtools/tree/abe811f66e1bd36612b76bbe28250bc669a6ce08/.vscode

Nim cannot open 'opencv/highgui'

I'm trying to use this library https://github.com/dom96/nim-opencv a wrapper for OpenCV.
After running nimble install opencv
I can see the package in ~/.nimble/pkgs/opencv-0.1.0/
But when attempting to use I get a compile error
Error: cannot open 'opencv/highgui'
import opencv/highgui
const fileName = "g.jpg"
let img_colr = loadImage(fileName, 1)
echo img_colr.width
echo img_colr.height
Not sure what the problem is something to do with Nim import paths?...
Are you compiling with nimble or nim? If the former then make sure you've got requires "opencv" in your .nimble file.

PyLint not recognizing cv2 members

I am running pylint on an opencv project and I am getting many pylint errors in VS code about members not being present.
Example code:
import cv2
cv2.imshow(....)
Errors obtained:
However , the code runs correctly without any errors.
Versions : pylint 1.8.1 , astroid 1.6.0
This is from pylint. You can generate a pylint config file in the root of your project with this command:
(I find this to be helpful if you work in a team or on different computers from the same repo)
pylint --generate-rcfile > ~/.pylintrc
At the beginning of the generated .pylintrc file you will see
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=
Add cv2 so you end up with
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=cv2
Save the file.
The lint errors should disappear.
On VScode: CTRL + Shift + P
Choose "Preferences: Open Settings (JSON)"
Add this line into JSON file:
"python.linting.pylintArgs": ["--generate-members"]
Done, it works for me
Note: Make sure you choose "Preferences: Open Settings (JSON)", not "Preferences: Open Default Settings (JSON)"
Setting File would look like
{
"workbench.iconTheme": "vscode-icons",
"python.dataScience.sendSelectionToInteractiveWindow": true,
"kite.showWelcomeNotificationOnStartup": false,
"python.dataScience.askForKernelRestart": false,
"python.dataScience.jupyterServerURI": "local",
"python.pythonPath": "/usr/bin/python3",
"workbench.colorTheme": "Monokai",
"vsicons.dontShowNewVersionMessage": true,
"python.linting.pylintArgs": ["--generate-members"] }
Try import cv2 like this:
from cv2 import cv2
Yes it is because the extension has not been installed.
Set this: extension-pkg-whitelist=cv2 and you're good to go.
However it may not detect the functions or modules implemented in cv2
Here the code snippet for the settings.json file in MS V Code
"python.linting.pylintArgs":["--extension-pkg-whitelist=cv2"]
I didn't have to change anything in the pylint Jason file like the most of the answers here My solution is to change the import statement to the form below
from cv2 import cv2
Eventually, cv2 members can be used!
In VSCode, edit the Settings JSON (Ctrl+Shift+P, > "Preferences: Open Settings JSON)
Then, paste the following into the JSON:
"python.linting.pylintArgs": [
... // prievious arguments
"--generated-members=cv2.*"
]
Don't know why, but other solutions (allowlist, etc) weren't working for me, and I didn't want ot create the .pylintrc file.
I used below config settings in settings.json of vscode and it helped me avoid the unessential flags by pylint, and also got intellisense for cv2 working,
it it doesn't work try uninstalling and deleting cv2 packages from C:\Anaconda3\envs\demo1\Lib\site-packages folder, and reinstalling opencv-python package
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=cv2"
]
}

Resources