Package not listed in requirements warnings in PyCharm - pip

PyCharm checks that every imported module (not in the standard lib) is in requirements.txt but for some modules (eg: grpcio vs grpc), the package name is different from the module name. Is there a way to silence the warnings in this case?

It's the bug in PyCharm, and it's still open: https://youtrack.jetbrains.com/issue/PY-11963
You can use #noinspection PyPackageRequirements to each import with this warning to suppress it.

Related

Error: code in directory ... expects import "..." - what do I do?

I have project in Go. After I set up debugger and launch in Visual Code,
it failed with this error output. I am using go 1.13.4 in /usr/local/go
/usr/lib/go-1.10/src/crypto/tls/cipher_suites.go:18:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/chacha20poly1305 expects import "golang.org/x/crypto/chacha20poly1305"
/usr/lib/go-1.10/src/crypto/x509/x509.go:36:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/cryptobyte expects import "golang.org/x/crypto/cryptobyte"
/usr/lib/go-1.10/src/crypto/x509/x509.go:37:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/cryptobyte/asn1 expects import "golang.org/x/crypto/cryptobyte/asn1"
/usr/lib/go-1.10/src/crypto/tls/key_agreement.go:20:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/curve25519 expects import "golang.org/x/crypto/curve25519"
/usr/lib/go-1.10/src/net/http/h2_bundle.go:48:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/net/idna expects import "golang_org/x/text/internal/export/idna"
/usr/lib/go-1.10/src/net/http/transport.go:32:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/net/proxy expects import "golang.org/x/net/proxy"
This seems to happen when you have a newer version of Go available on your PATH.
I worked around it by uninstalling Go 1.13 from /usr/local, but there may be better ways to handle it if you need to have multiple versions installed.
I had the VSCode Go debugger working with go.goroot set to a Go 1.11 install I was using for my project. I installed Go 1.13 into /usr/local to test out a feature and then ran into this same error.
If you have a different Go version on the PATH it seems like it's using that compiler, but compiling against the standard library sources in your other Go version. In later Go versions this directory has been renamed back to vendor/golang.org, and it doesn't recognize the golang_org hack that was used previously:
https://github.com/golang/go/commit/4d00937cecdea85b6f1eb894a6d28a53f5f2ff8a#diff-44c7c5a1dcc556d22e115d30ec0f11c9
I'm not certain if this is a general problem with Delve, or an issue with how the VSCode Go extension calls it, but the simplest solution in my situation was to uninstall Go 1.13 and the debugger started working again.
Your problem has nothing to do with the debugger. If you would have searched for the key parts of these errors, you would have discovered that the error is due to the fact since v1.4 Go supports so-called "canonical imports".
Most probably some packages in your project were vendored using their "hosting" URLs (such as github.com/what/ever) instead of their canonical URLs suggested by the error message.
The proper solution is to revendor the affecting packages the correct way.
If you merely want the code to build "as is" no matter what, you could edit the code of these packages to remove "canonical import comments" from them.

Go Modules does not recognize files under GOPATH

I was trying to set up GO Modules in intellij and was trying import a package under GOPATH. When I use Go Modules, it doesnt seem to 'import' the packages from GOPATH. Any ideas on what I could be doing wrong?
Below is a screenshot. Left pic: GoModules, which doesnt recognize the package. Right Pic: Simple GO project, which recognized the packages.
I tried doing sync package, with no luck.
Go version - 1.12.3
.
The two supported modes ("GOPATH mode" and "module-aware mode") are mutually exclusive modes. This means you can't have both, you can't mix modules and GOPATH.
Quoting from Command go: GOPATH and Modules:
When using modules, GOPATH is no longer used for resolving imports. However, it is still used to store downloaded source code (in GOPATH/pkg/mod) and compiled commands (in GOPATH/bin).
And also Command go: Preliminary module support:
For more fine-grained control, the module support in Go 1.11 respects a temporary environment variable, GO111MODULE, which can be set to one of three string values: off, on, or auto (the default). If GO111MODULE=off, then the go command never uses the new module support. Instead it looks in vendor directories and GOPATH to find dependencies; we now refer to this as "GOPATH mode." If GO111MODULE=on, then the go command requires the use of modules, never consulting GOPATH. We refer to this as the command being module-aware or running in "module-aware mode". If GO111MODULE=auto or is unset, then the go command enables or disables module support based on the current directory. Module support is enabled only when the current directory is outside GOPATH/src and itself contains a go.mod file or is below a directory containing a go.mod file.
In module-aware mode, GOPATH no longer defines the meaning of imports during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod) and installed commands (in GOPATH/bin, unless GOBIN is set).
If you wish to use packages located on your disk, see How to use a module that is outside of "GOPATH" in another module?
I faced this problem, and I use this setting for each project, and it solved my problem.
But I'm still looking for a global GO module configuration.

Using modules, newly installed package cannot be referenced within project

go version go1.11.4 darwin/amd64
GOPATH has been unset but was previously set to $HOME/Development/go
Project path is under $HOME/code/
I’m able to successfully (no errors at least) install the go-sql-driver/mysql package using the command
go get github.com/go-sql-driver/mysql#v1
When I include a reference to that package in an import statement
import(
_ "github.com/go-sql-driver/mysql")
in my code I see the error
could not import github.com/go-sql-driver/mysql (can’t find import:
“github.com/go-sql-driver/mysql”)
I have run go mod init in my project root and it creates a go.mod file. When I run the go get command I see a require statement added to that file for the package. But it seems the files for the package get installed in the default $HOME/go directory (since I've unset GOPATH).
Should I be doing things differently so that my import statement can find the newly installed package? Using modules shouldn't all the packages be installed in the project path somewhere?
Should I be doing things differently so that my import statement can find the newly installed package?
No. With modules there is no need to install the packages upfront at all.
Using modules shouldn't all the packages be installed in the project path somewhere?
No. They get downloaded somewhere in some format and used from that location but they are not "installed" like in the old GOPATH variant of go get.
Show output of go env and what go mod vendor produces.
I'm pretty sure I was doing things wrong. I was able to resolve this after referencing the following closely the steps documented at golang modules wiki. The summary is that there is no need to "install" a package via 'go get'. Instead simply make sure your project is initialized to use modules using the 'go mod init' command and then include the package name in an import statement. The next build event will pull down the package and all its dependencies.

ModuleNotFoundError: No module named 'yaml'

I have used a YAML file and have imported PyYAML into my project.
The code works fine in PyCharm, however on creation of an egg and running the egg gives an error as module not found on command prompt.
You have not provided quite enough information for an exact answer, but, for missing python modules, simply run
py -m pip install PyYaml
or, in some cases
python pip install PyYaml
You may have imported it in your project (on PyCharm) but you have to make sure it is installed and imported outside of the IDE, and on your system, where the python interpreter runs it
I have not made an .egg for some time (you really should be consider using wheels for distributing packages), but IIRC an .egg should have a requires.txt file with an entry that specifies dependency on pyyaml.
You normally get that when setup() in your setup.py has an argument install_requires:
setup(
...
install_requires=['pyyaml<4']
...
)
(PyYAML 4.1 was retracted because there were problems with that version, but it might be in your local cache of PyPI as it was in my case, hence the <4, which restricts installation to the latest 3.x release)

Can't import win32crypt python module

I have the 32 bit version of python 3.4 installed. I'm trying to use the win32crypt module after installing pywin32 but I get the following error message in git CLI:
import win32crypt
ImportError: DLL load failed: The specified module could not be found.
As recommendedhere, I used dependency walker on the win32crypt.pyd file (located at C://Python34/Libsite-packages/win32 on my computer) and several dll are missing: PYTHON34.dll, PYWINTYPES34.DLL, GPSVC.DLL, IESHIMS.DLL.
Are these missing dll likely to cause the import failure? If so, how can I fix this?
A more modern solution:
pip install pypiwin32
This contains .whl files to aid in installing on Windows.
You don't need to copy/paste any dll, simply add the pywin32 module to the windows environment variable Path. Default is: "C:\Python34\Lib\site-packages\pywin32_system32".
Please note that dependency walker still shows missing dll, so maybe it is of doubtful utility in some cases.
I try to use python x64, and it work.
another solution is that you can copy 2 dll files from "C:\Python34\Lib\site-packages\pywin32_system32" and paste them where ur .py file location is,and then use the command --add-data ".*.dll;." just make sure there're no more dll files but these two in this path. this is suitable when you are using '-F' command

Resources