SOLVED. Apparently I somehow deactivated my Conda environment. Typing Conda: Activate Environment into the Sublime console fixed it.
I'm using Anaconda3 to run scripts developed at my workplace. I had set up SublimeText to view/edit the scripts and to run them using the build command. Until today, I had been able to run scripts normally.
Today, however, some of the commands are not enclosed with white boxes and I get an error command which trying to build the script.Here's a screenshot showing the markings and error message
I first restarted my computer to no avail. I then uninstalled and re-installed packages for Conda and Anaconda but that also failed to fix it. Googling "sublime conda not building" gave me results which concerned error messages while building a script and not being unable to build entirely. I also can't find a match to my specific error message.
Any insight? If it's not obvious, I am a novice to python & sublime. Thanks.
EDIT: The white boxes are now gone. More importantly, apparently they're related to linting and are (likely) not related to the script not building which is the primary concern.
EDIT2:
URLS for plugins Conda and Anaconda
I wasn't able to find conda.sublime-build, but I found conda.sublime-settings which I think is the same thing. If not, please let me know where to look. (this was under user packages). These settings are pasted below.
// Default Windows settings for sublime-text-conda:
{
// executable is the path to anaconda's python
// this python executable is used in order to find conda
"executable": "C:\\Users\\26036\\Anaconda3\\python.exe",
// Directory in which the conda envs are stored
// Default location is the user's home directory
"environment_directory": "C:\\Users\\26036\\Anaconda3\\envs\\",
// System architecture for Python installation
// options: 32 or 64 bit
"architecture": "64",
// configuration is the path to conda's configuration file
"configuration": "~\\.condarc",
// when true, the scripts will be run through the shell
// If your code has a GUI (e.g. a matplotlib plot),
// this needs to be true, otherwise Windows suppresses it.
"run_through_shell": false,
// when true, the script execution will be handed over to
// the pythonw executable, instead of python
"use_pythonw": false,
// open repl in second row tab below current file,
// closing any existing tabs in that area
// assumes files are kept in group 0 (typical)
"repl_open_row": false,
// when opening a repl using repl_open_row, close any
// existing conda repls in the second row first
"repl_row_close_existing": false,
// save the current file (if dirty) when opening repl
"repl_save_dirty": true,
// syntax highlighting for Open REPL command
// choice between 'python' and 'plaintext'
"repl_syntax": "python"
}
EDIT3: I have both Conda and Anaconda3 packages installed. When it was working, I selected Conda as my build system. I'm sorta sure the environment was activated because I was able to run the script beforehand but perhaps the environment got deactivated?
Turns out my Conda environment was somehow made inactive. Typing "Conda: Activate Environment" in the Sublime Console fixed it. Thanks MattDMo for suggesting I check it.
My vscode does not detect errors in golang.
Example:
package somepackage
import "fmt"
func f(name string) string {
name = 1
return name
}
This should throw a type error, but it does not. I never get any errors.
My settings.json contains
"go.gopath": "some/path",
"go.vetOnSave": "package",
"go.lintOnSave": "package",
"go.testOnSave": true,
"go.buildOnSave": "package",
"go.coverOnSave": true
I was able to run go: install/update Tools. All tools are installed successfully.
I am also able to run debug a .go file in vscode.
As #pwaterz pointed out, the solution to my problem was to add "go.goroot: /some/other/path".
The reason that vscode was not able to detect errors was, that there are different go versions on my computer. Adding the goroot and running go: install/update Tools solved the problem.
---- Edit: Multiple go versions ----
Had multiple conflicting go versions on my Mac, pulled in via brew. Fixed the problem with a reinstall.
Uninstall go and also run brew uninstall go
Reinstall go
Set environment variables in your .bash_profile or similar. Compare here.
Apply the changes to your profile by running e.g. source .bash_profile
Restart VSCode
In settings.json set "go.goroot": "/usr/local/go"
Run go: Toggle workspace trust space to make sure changes to settings.json are applied (you have to trust your workspace for that)
go: Install/update tools and select all
---- Edit: Incorrect root folder ----
Make sure that you open the root folder of your project and not a sub-folder of your project. That may cause in invalid import paths otherwise
---- Edit: Broken language server ----
Try to run go: restart language server
You may see Error loading workspace
run go mod tidy and try again
I'm trying to install Go, gRPC and Protobuf but I cant even install Go in the first place.
I followed steps mentioned in this site:
https://tecadmin.net/install-go-on-centos/
My bash_profile file looks like this now:
http://prntscr.com/nf2bm9
And when I try to test go installation by typing "go version" in the console I get this error:
-bash: go: command not found
Where did I go wrong?
Note: I navigated to /usr/local/ to see if there is any go folder with files or not to confirm the files has been downloaded and moved at the right place.
Changes to your .bash_profile file only take effect after you relaunch the terminal.
source ~/.bash_profile will reload it in your current session, if you'd rather take that approach.
I am getting started with Go and would like to use Visual Studio Code for editing. I successfully installed go on my Ubuntu Computer.
My GOPATH (go env) is set to the same value as go.gopath in settings.json. If I run Go: Current GOPATH it outputs the correct path.
However, I am not able to install the go extensions. If I click on Install all I get output similar to this:
Installing 1 tool at home/jan/go/bin
dlv
Installing github.com/go-delve/delve/cmd/dlv FAILED
1 tools failed to install.
dlv:
Error: Command failed: /snap/bin/go get -u -v github.com/go-delve/delve/cmd/dlv
I seem to be able to just install packages manually with /snap/bin/go get -u -v github.com/go-delve/delve/cmd/dlv. The command runs without errors, but VSCode seems to be unable to find dlv.
My settings.json:
{
"terminal.integrated.rendererType": "dom",
"go.useLanguageServer": true,
"go.formatTool": "gofmt",
"go.lintOnSave": "file",
"go.vetOnSave": "package",
"go.buildOnSave": "package",
"go.lintTool": "golint",
"go.gopath": "home/jan/go"
}
I have git installed on my computer. It works without a problem.
Your GOPATH is not set correctly in settings.json.
"go.gopath": "home/jan/go"
This path is relative, and so it would be appended to whatever your working directory is, with the obvious result of not being able to find the path as it won't exist.
You can either set it correctly, or delete it and the GOPATH environment variable will be used. (I run it this way.)
"go.gopath": "/home/jan/go"
I am getting this error when I tried to run an example helloworld code I got onlie.
compile: version "go1.9" does not match go tool version "go1.9.1"
My computer has go1.9.1. What does the error mean and how can I fix this?
If you are installing using OSX homebrew you may need to set the $GOROOT in your .bashrc, .zshrc, etc:
export GOROOT=/usr/local/opt/go/libexec
I had the same error this morning when I updated from 1.9 -> 1.9.1 though according to several post the $GOROOT shouldn't have to be set and I had not set it until today. This may be a bug?
Edit: not a bug, for more details see answer below.
This is a mismatch between the GOROOT environment variable and the default path to your go command. One or the other needs to be changed; the one that needs to be changed depends on the specific setup on your computer. You could determine this by updating your Go to the latest version using your preferred method, running either which go (on Linux/macOS/BSD) or where go (on Windows), and then checking which of the files listed has the newer timestamp.
Linux/macOS/BSD
To change the GOROOT to match the default path of your go command, run type go and strip off the /bin/go part at the end to yield the directory path containing your Go installation. Then, add it to your .bashrc or other appropriate init file like this:
export GOROOT=/path/to/go-installation
To instead change the go command path to match your GOROOT, add this to the bottom of your init file:
export PATH="${GOROOT}/bin:${PATH}"
Windows
To change the GOROOT to match the default path of your go command, run where go take the first line of output, and strip off the \bin\go.exe part at the end. Then, go to "Edit the system environment variables" in Settings, click "Environment Variables...", find the "GOROOT" variable and edit to read the path you created earlier.
To instead change the go command path to match your GOROOT, first save the output of echo %GOROOT%\bin. Then, go to "Edit the system environment variables" in Settings, click "Environment Variables...", and find the
find the "Path" row in the bottom pane, click New, put in the path you created earlier, and finally click Move Up until it's at the top.
All
You'll need to open up a new command prompt to see the effects.
in case you are using mac with homebrew, just run:
brew cleanup
to clean all the legacy package, this fixed my problem.
In mac OS , if you downloaded and installed go package without brew, running brew update commands will cause this problem to occur
for fix this problem you can do :
brew uninstall --ignore-dependencies go
uninstalling go from brew will fix problem
This error happens when you forgot to delete previous golang install ... just delete its directory ... so identify go install location ... on linux issue
type go
typical output is
go is hashed (/usr/local/go/bin/go)
so just remove its grandparent directory ( go install dir not just the go binary )
sudo rm -rf /usr/local/go # NOTE this is not /usr/local/go/bin/go
now just install go and you'll be fine
For M1 Mac, the following steps helped me!
Check for which go from VSCode Terminal and check from system terminal.
from vscode terminal
user#mac % which go
/usr/local/go/bin/go
from my mac terminal
user#mac % which go
/opt/homebrew/bin/go
Whichever corresponds to the GOROOT shown go env, keep it and delete the other one
user#mac % go env GOROOT
/usr/local/go
in this case
rm -rf /opt/homebrew/bin/go
close and reload the vscode and terminal
For Windows delete the GOROOT System variables in the Enviroment Variables and restart the PC.
if you use VsCode, you just add this in setting.json.
"go.goroot": "/usr/local/Cellar/go/1.x.x/libexec",
For me, it's caused by GOROOT env, using gotip before, change to brew version.
# curret go env
cat "$(go env GOENV)"
# make sure this is correct
go env GOROOT
# unset GOROOT if setted before
go env -u GOROOT
you may also want to set a proper GOROOT to match the go version.
In my case, I had a scripts that look like this:
[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"
Hanging around in my .bashrc/.zshrc file from a previous installation of go / trying to use gvm.
Removing this and restarting terminal solved it for me.
I had the same issue when I used getgo to update my Go version from 1.19 to 1.20. In my case, getgo created a .bash_profile and set its own export path w/c is not consistent with what's in my .bashrc.
#my .bash_profile;
export PATH=$PATH:/home/user/.go/bin
export PATH=$PATH:/home/user/go/bin
#my .bashrc;
export GOROOT=/usr/local/go/
export GOPATH=$HOME/go
export PATH=$PATH:$/home/user/go/bin:$GOROOT/bin:$PATH
SOLUTION:
I just replaced my export PATH in bashrc w/
export PATH=$PATH:$/home/user/.go/bin:$GOROOT/bin:$PATH
<Note the '.go' change w/c is now consistent to what's in my .bash_profile>.
So whether source is ~/.bashrc or ~/.bash_profile, it will always point to the same path for Go. Hope this helps. I'm also new to Go and Ubuntu. I know how painful it is to get these variables right on your own.
Took a simple approach(Linux), I had different versions of Go installed in my system.
$ whereis go
helped me to find the available go runnables, removed all, installed a fresh one and ensured to create a link for this new Go runnable in one of the $PATH folder to ensure below gives the correct version of what installed now.
$ go version