Tried to install github.com/go-sql-driver/mysql but there's an error when I tried importing - go

First i created a folder called sqltest the run the go mod init. And then I installed the mysql by running the code below
go get -u github.com/go-sql-driver/mysql
However when I tried to import "github.com/go-sql-driver/mysql, it has an error
it says could not import github.com/go-sql-driver/mysql (no required module provides package "github.com/go-sql-driver/mysql")compilerBrokenImport
I tried to delete the go-sql-driver and re-install it but nothing happens

Does the import look like?
import (
_ "github.com/go-sql-driver/mysql"
)

Related

golang ambiguous import using SDL

i am trying to get sdl working on linux mint and golang, i hav tried to install it using the commands on the github page and the i tried importing it
package main
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
)
but when ever i try to run it go buld main.go it spits out this error
main.go:6:2: ambiguous import: found package github.com/veandco/go-sdl2/sdl in multiple modules:
github.com/veandco/go-sdl2 v0.4.25 (/home/user/go/pkg/mod/github.com/veandco/go-sdl2#v0.4.25/sdl)
github.com/veandco/go-sdl2/sdl (/home/user/Desktop/golang/gui)
i have tried removing the file and re-installing it but it doesn't seem to work, i know it's probely my fault it's not working, thanks in advance (sorry for any bad english or grammer)

How should I resolve this import problem with gorilla/mux?

could not import github.com/gorilla/mux (cannot find package "github.com/gorilla/mux" in any of
C:\Program Files\Go\src\github.com\gorilla\mux (from $GOROOT)
C:\Users\lenovo\go\src\github.com\gorilla\mux (from $GOPATH))compilerBrokenImport
I have installed gorilla mux using the cmd "go get github.com/gorilla/mux" but I'm getting this error.enter image description here
Looks like you didn't run "go mod init" before the "go get".
In cmd, try this:
cd [the dir of your source code]
go mod init
go get github.com/gorilla/mux
For more information run:
go help mod
Afterwards, you might also need to restart VS Code.

"Error: package not found" even after using pip to install

I have successfully finished the first problem I had with pip.main being moved, but I installed pyfirmata which I am using for my Arduino UNO, but even though I used pip and successfully installed it, there was still an error that said "package pyfirmata not found". I don't understand this. This is my code:
#install pyfirmata
import pip
from pip._internal import main as pipmain
pipmain(['install', 'pyfirmata'])
#import pyfirmata
from pyfirmata import Arduino, util
import time
board = Arduino('') #put port into "('')"
if you are getting error no module named pyfirmata and it is sucessfully installed than again type pip install pyfirmata you see requirment satisfy and location of site packages open location search pyfimata and locate pyfirmata file to your project directory
now it possible pyfirmata need more module so also locate them with in the directory

Cannot find package under GOPATH

I am trying to install the dependencies of my project with glidebut unfortunately it fails with the following message:
main.go:7:2: cannot find package "github.com/arschles/go-in-5-minutes/episode13/models" in any of:
/Users/theo/go-workspace/src/github.com/thitami/go-in-5-minutes/episode13/vendor/github.com/arschles/go-in-5-minutes/episode13/models (vendor tree)
/usr/local/Cellar/go/1.8.3/libexec/src/github.com/arschles/go-in-5-minutes/episode13/models (from $GOROOT)
/Users/theo/go-workspace/src/github.com/arschles/go-in-5-minutes/episode13/models (from $GOPATH)
Running a go env, this is my env variables of interest:
GOPATH="/Users/theo/go-workspace"
GOROOT="/usr/local/Cellar/go/1.8.3/libexec"
Please be advised that I am zsh and I am exporting the GOPATH inside the .zshrc file like this:
export GOPATH=HOME/go-workspace
Any ideas are appreciated
* UPDATE *
As requested this is the piece of code with the call to the models package:
import (
"database/sql"
"log"
"github.com/arschles/go-in-5-minutes/episode13/models"
_ "github.com/mxk/go-sqlite/sqlite3"
)
You can only set the gopath once and you'll have to reset it every time you change packages. Think of it as a virtualenv. One way around it is to install the packages global or by using something like gvm

import object is expected Error in Golang 1.4.2

I have just upgraded Golang from 1.3 to version 1.4.2. And cannot compile due to error:
../../my/mandrill.go:5: import /path/to/go/home/pkg/darwin_amd64/github.com/keighl/mandrill.a: object is [darwin amd64 go1.3.3 X:precisestack] expected [darwin amd64 go1.4.2 X:precisestack]
FAIL folder [build failed]
on line m "github.com/keighl/mandrill"
package my
import (
"fmt"
m "github.com/keighl/mandrill"
)
I guess some rules of importing have changed in 1.4.2. But cannot figure out how to change my import code to make it compile.
Just delete the old pkg files, usually it upgrades automatically though.
rm -rf $GOPATH/pkg/
I met this problem too. I deleted the old packages but still get same error. finally I found the old pkg keep get generated by my "sublime text2". after restarted it. everything back to work :p

Resources