import fuction from package to another package - path

can you please tell me how can I import a function from poly.py to query.py
this is the directories tree :
my_project
|_dataset
|_execute
|__poly.py
|_search
|__query.py
|_determine
|_optimize
|_transmit
NB : my python version is 3.6.2 > 3.3 so _init.py is unuseful

You need put those files in 1 folder and do import filename or from filename import function

Related

How do I embed the version from pyproject.toml so my package can use it?

The version in my project is stored in pyproject.toml:
[tool.poetry]
name = "package_name"
version = "1.2.3"
# ...
I now want to have a __version__ in package_name/__init__.py as well and the general suggestion seems to be:
import importlib_metadata
__version__ = importlib_metadata.version('package_name')
But that doesn't work for me. The moment I run my unittests I get this error:
importlib_metadata.PackageNotFoundError: No package metadata was found for package_name
How can I make this work during development?
You can try add this to __init__:
from ._version import version as __version__
source

ModuleNotFoundError seen from module being imported from different folder on module being imported from same folder

Folks, sorry for the convoluted question title
I have the following dir structure:
projectfolder/source
- main.py
- module1.py
- module2.py
projectfolder/tests
- test-module1.py
- test-module2.py
module2.py imports module1.py, test-module1.py works just fine, I added
import sys
sys.path.append("..")
in test-module1.py and imported source.module1
but when I try to run test-module2.py(with the same import sys and sys.path.append(...)) I get
File "../source/module2.py", line 1, in
from module1 import *
ModuleNotFoundError: No module named 'module1'
What am I doing wrong? Also this is my first python project I am building from scratch, what is the recommended dir structure? should main be in the projectfolder root?
This is python3 so there is no need for init.py I think..

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

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

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" />

Imports failed in Config.groovy file (Grails 2.2.3)

I try to run a grails app thanks to grails run-app command. Version I use is grails 2.2.3.
All imports failed and I've got the "unable to resolve class" about all import line. For example :
unable to resolve class com.octo.captcha.component.image.backgroundgenerator.GradientBackgroundGenerator
Errors are about the following lines :
import com.octo.captcha.service.multitype.GenericManageableCaptchaService
import com.octo.captcha.engine.GenericCaptchaEngine
import com.octo.captcha.image.gimpy.GimpyFactory
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator
import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage
import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator
import com.octo.captcha.component.image.backgroundgenerator.GradientBackgroundGenerator
import com.octo.captcha.component.image.color.SingleColorGenerator
import com.octo.captcha.component.image.textpaster.NonLinearTextPaster
Here you can read these 2 files : Config.groovy and the return of "grails run-app" to help you : http://dl.free.fr/vPbCJEUnN
Thanks for your help !

Resources