Intellij Golang cannot find a module - go

I am using Golang plugin for IntelliJ, after set the GO Sdk for the module and project. I tried to edit configuration for the project. When I click the edit configuration, in module dropdown box, it shows no module. it seems the configuration cannot find the module. Anything that I missed? I have issue the following command in order to make Go SDK work in Intellij.
# mkdir /usr/lib/go/bin
# ln -s /usr/bin/go /usr/lib/go/bin/go
# ln -s /usr/bin/godoc /usr/lib/go/bin/godoc
# ln -s /usr/bin/gofmt /usr/lib/go/bin/gofmt

In the recent version of IntelliJ (here is screenshot from Ultimate 2019.1.3) you can find the GOROOT and GOPATH in Preferences -> Language & Frameworks -> Go -> GOROOT/GOPATH.
Install to Golang in your system (I used brew):
Since OSX ElCapitan, the OSX forbid access to /bin directory, which would cause problems with compiling the project with the default settings and having error like:
Cannot run program "/bin/go" (in directory "/Users/XXX/go/src/YYY/ZZZ/service"): error=2, No such file or directory
So this should be solved by updating GO preferences.
Open IntelliJ and your go project and update GOROOT in your project
If you have a custom directory of GOPATH do update it as well.
Click to run your go program.

Try the recent latest releases of that plugin, to see if the issue persists.
Note that you shouldn't have to link anything, just set your $GOROOT environment variable (or not, as mentioned in this article), and your $GOPATH.

this works for me:
Close GoLand.
Navigate to the project root, backup and delete .idea
directory.
Open the IDE again.
by https://youtrack.jetbrains.com/issue/GO-11854

Related

Install adt Package [duplicate]

In PyCharm, I've added the Python environment /usr/bin/python. However,
from gnuradio import gr
fails as an undefined reference. However, it works fine in the Python interpreter from the command line.
GNURadio works fine with python outside of Pycharm. Everything is installed and configured how I want it.
Gnuradio is located at /usr/local/lib/python2.7/site-packages/gnuradio
Also:
PYTHONPATH=/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/site-packages/gnuradio
Adding a Path
Go into File → Settings → Project Settings → Project Interpreter.
Then press configure interpreter, and navigate to the "Paths" tab.
Press the + button in the Paths area. You can put the path to the module you'd like it to recognize.
But I don't know the path..
Open the python interpreter where you can import the module.
>> import gnuradio
>> gnuradio.__file__
"path/to/gnuradio"
Most commonly you'll have a folder structure like this:
foobarbaz/
gnuradio/
__init__.py
other_file.py
You want to add foobarbaz to the path here.
You should never need to modify the path directly, either through environment variables or sys.path. Whether you use the os (ex. apt-get), or pip in a virtualenv, packages will be installed to a location already on the path.
In your example, GNU Radio is installed to the system Python 2's standard site-packages location, which is already in the path. Pointing PyCharm at the correct interpreter is enough; if it isn't there is something else wrong that isn't apparent. It may be that /usr/bin/python does not point to the same interpreter that GNU Radio was installed in; try pointing specifically at the python2.7 binary. Or, PyCharm used to be somewhat bad at detecting packages; File > Invalidate Caches > Invalidate and Restart would tell it to rescan.
This answer will cover how you should set up a project environment, install packages in different scenarios, and configure PyCharm. I refer multiple times to the Python Packaging User Guide, written by the same group that maintains the official Python packaging tools.
The correct way to develop a Python application is with a virtualenv. Packages and version are installed without affecting the system or other projects. PyCharm has a built-in interface to create a virtualenv and install packages. Or you can create it from the command line and then point PyCharm at it.
$ cd MyProject
$ python2 -m virtualenv env
$ . env/bin/activate
$ pip install -U pip setuptools # get the latest versions
$ pip install flask # install other packages
In your PyCharm project, go to File > Settings > Project > Project Interpreter. If you used virtualenvwrapper or PyCharm to create the env, then it should show up in the menu. If not, click the gear, choose Add Local, and locate the Python binary in the env. PyCharm will display all the packages in the selected env.
In some cases, such as with GNU Radio, there is no package to install with pip, the package was installed system-wide when you install the rest of GNU Radio (ex. apt-get install gnuradio). In this case, you should still use a virtualenv, but you'll need to make it aware of this system package.
$ python2 -m virtualenv --system-site-packages env
Unfortunately it looks a little messy, because all system packages will now appear in your env, but they are just links, you can still safely install or upgrade packages without affecting the system.
In some cases, you will have multiple local packages you're developing, and will want one project to use the other package. In this case you might think you have to add the local package to the other project's path, but this is not the case. You should install your package in development mode. All this requires is adding a setup.py file to your package, which will be required anyway to properly distribute and deploy the package later.
Minimal setup.py for your first project:
from setuptools import setup, find_packages
setup(
name='mypackage',
version='0.1',
packages=find_packages(),
)
Then install it in your second project's env:
$ pip install -e /path/to/first/project
For me, it was just a matter of marking the directory as a source root.
Add path in PyCharm 2017
File -> Settings (or Ctrl+Alt+S) -> Project -> Project Interpreter
Show all
Select bottom icon on the right side
Click on the plus button to add new path to your module
My version is PyCharm Professional edition 3.4, and the Adding a Path part is different.
You can go to "Preferences" --> "Project Interpreter". Choose the tool button at the right top corner.
Then choose "More..." --> "Show path for the selected interpreter" --> "Add". Then you can add a path.
DON'T change the interpreter path.
Change the project structure instead:
File -> Settings -> Project -> Project structure -> Add content root
In PyCharm 2020.1 CE and Professional, you can add a path to your project's Python interpreter by doing the following:
1) Click the interpreter in the bottom right corner of the project and select 'Interpreter Settings'
2) Click the settings button to the right of the interpreter name and select 'Show All':
3) Make sure your project's interpreter is selected and click the fifth button in the bottom toolbar, 'show paths for the selected interpreter':
4) Click the '+' button in the bottom toolbar and add a path to the folder containing your module:
For PyCharm Community Edition 2016.3.2 it is:
"Project Interpreter" -> Top right settings icon -> "More".
Then on the right side there should be a packages icon. When hovering over it it should say "Show paths for selected interpreter". Click it.
Then click the "Add" button or press "alt+insert" to add a new path.
As quick n dirty fix, this worked for me:
Adding this 2 lines before the problematic import:
import sys
sys.path.append('C:\\Python27\\Lib\site-packages')
On Project Explorer, you can right click on the folder where the module is contained and set as 'Source'.
It will be parsed in the Index for code completion as well as other items.
I'm new to PyCharm (using 2018.3.4 CE) and Python so I rotely tried to follow each of the above suggestions to access the PIL (Pillow) package which I knew was in system-site-packages. None worked. I was about to give up for the night when I happened to notice the venv/pyvenv.cfg file under my project in the Project Explorer window. I found the line "include-system-site-packages = false" in that file and so I changed it to "true". Problem solved.
In my PyCharm 2019.3, select the project, then File ---> Settings, then Project: YourProjectName, in 'Project Interpreter', click the interpreter or settings, ---> Show all... ---> Select the current interpreter ---> Show paths for the selected interpreter ---> then click 'Add' to add your library, in my case, it is a wheel package
For me there is also another issue. If you try to add a folder that in the past had a .idea folder, but your current project has it's own .idea folder your pycharm might get confused for some reason -- even if you have the right python/conda env. For me deleting the .idea folder of the other project fixed the confusion that it could find the obviously correctly installed pkgs. Then it was it was able to find them in the pycharm editor GUI snf stopped underlyinging them in red.
Download anaconda
https://anaconda.org/
once done installing anaconda...
Go into Settings -> Project Settings -> Project Interpreter.
Then navigate to the "Paths" tab and search for /anaconda/bin/python
click apply

What does Enable Go modules integration do in Intellij IDE

Not having previous knowledge about creating a project from zero within terminal, I've created a folder, cd into of it then run go mod init my_project_name which created a go.mod file for me, then I've created main.go file which built just ok.
Then I created a folder and add a go file inside with package name (being same with directory) and create a struct inside of it. Next I tried to import that package in main package but when I try to build on terminal it gave me this error
go: cannot determine module path for source directory /Users/berkcan/workspace/go/my_project_name (outside GOPATH, module path must be specified)
After googling and not being able to find a solution to my problem, I've imported project to beloved Intellij IDE and I enabled Go modules integration then everything worked flawlessly. First I thought IDE doing some magic inside while building project but even when I try go build command in terminal, it built. But I cant see difference in project structure or a new line in go.mod file.
So what happened, what did Intellij IDE did when I ticked go module integration box and what I can do enable it on terminal without Intellij IDE ?
here is the photo of option in IDE when ticked
IntelliJ IDEA plus Go plugin or GoLand under the hood has two modes to get the information about your packages (simplified):
GOPATH. IDEA scans your $GOPATH directory to build internal indexes of your packages and provides code completion, resolving, etc.
Go Modules. IDEA executes go list -m -json to resolve your dependencies and scans your $GOPATH/pkg/mod directory (default value of GOMODCACHE) for the packages. If they don't exist, IDEA executes go mod download. After these operations, the IDE provides all built-in features like code completion, navigation and so on.
Both modes don't change your Go or environment variables as well as behavior in the terminal. When you check Enable Go Modules integration option in the settings, the IDE just switches the mode from scan $GOPATH to execute go list and resolve your dependencies from the Go Modules cache.
To summarize, IntelliJ IDEA doesn't do any magic. I suppose it relates to your custom Go environment variables inside the terminal, especially GO111MODULE and if you didn't pass these variables to the GUI apps (e.g. you have specified it in .zshrc file and run the IDE via Desktop entry instead of the terminal), IntelliJ IDEA doesn't inherit them. You can compare go env output inside your local terminal and built-in inside the IDE (View | Tool Windows | Terminal) and find differences.

How can make my GoLand to detect dependency packages under $GOPATH/pkg/mod?

I'm trying through kubebuilder tutorial, and just imported existing project to GoLand.
Workthrough with kubebuilder auto-generated scaffold codes, and auto-downloaded pkgs with go mod for me. I had no problem when I was working with commandline environment, but turns out, after opening the project with GoLand, IDE is failing to resolve imported package names, which means it is failing to detect - or link - packages installed by go mod.
I enabled go mod(with vendoring) and dep both from IDE preferences, set GOPATH and Go runtime properly, but the error keeps to appear.
I don't know why I'm getting this error, and how to solve it.
+) Working Directory is $GOPATH/src/example, all the logics and settings are placed in the directory. Installed dependencies are placed under $GOPATH/pkg/mod.
I enabled go mod(with vendoring) and dep both from IDE preferences, set GOPATH and GOROOT properly, but the error keeps to appear.
Let's assume that you have the following setup on your machine:
Go is installed under /usr/lib/go
GOPATH is set to /home/florin/go
the KubeBuilder project named demobuilder is created under /home/florin/projects/demobuilder. I recommend this as opposed to using GOPATH, as you do, for Go Modules projects because they behave in a different way while in GOPATH.
First, make sure that you have GoLand 2019.3.1 or newer.
Then, after creating the demobuilder project, start GoLand, then click on the Open Project button.
When the project is opened, if you have not configured yet, the IDE will ask you for the Go SDK configuration, aka GOROOT. It will be a yellow bar at the top of the editor. Click on the link on the right side to configure it. You can select the local installation and point it to /usr/local/go. If you don't have Go installed, you can also download it in a directory of your choice.
Then, the IDE should automatically notice that the project is a Go Modules based project and enable the support for them. If it's not, then go to Settings/Preferences | Go | Go Modules and enable that. DO NOT enable both Go Modules and dep support at the same time. If you did that, disable the dep integration and try again.
You can see all of these in the help page.
Is Go modules integration enabled via File | Settings | Languages & Frameworks | Go | Go Modules

How to install VTK 6.1 for OSX 10.8 with Cocoa/XCode support?

The extremely helpful guidelines posted at http://www.vtk.org/Wiki/Cocoa_VTK and via the readme file by Sean McBride and Mike Jackson inside the VTK repo were slightly out of date for VTK 6.1. So in case this helps anybody, I'm posting instructions for installing VTK 6.1 on OSX 10.8 with support for the SimpleCocoaVTK Xcode project.
* Installing VTK 6.1 for OSX 10.8 with Cocoa support *
These instructions slightly modify Ryan Glover's instructions at http://www.vtk.org/Wiki/Cocoa_VTK and the README.rtf in the VTK/Examples/GUI/Cocoa/Documentation folder by Sean McBride and Mike Jackson.
Clone the VTK git repo into a directory of your choice:
cd /Users/you/
git clone https://github.com/Kitware/VTK.git
cd VTK
git checkout tags/v6.1.0
make a build directory
mkdir VTKBuild
cd VTKBuild
Run the VTK cmake script
You will now be inside /Users/you/VTK/VTKBuild, run cmake from here (using the parent directory's CMake files):
cmake ..
Edit lots of lines in the newly generated CMakeCache.txt (in the current VTKBuild directory). One issue I had was that there were error if I didn't use a full path for the CMAKE_INSTALL_PREFIX. So make sure to use "/Users/you/" instead of "~":
CMAKE_INSTALL_PREFIX:PATH=/Users/you/VTK/VTKBuild
BUILD_SHARED_LIBS:BOOL=OFF
CMAKE_BUILD_TYPE:STRING=Debug
VTK_USE_SYSTEM_ZLIB:BOOL=ON
CMAKE_OSX_ARCHITECTURES:STRING=i386;x86_64
CMAKE_OSX_SYSROOT:STRING=/Applications/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
Compile the VTK project (this might take over an hour to run!):
make
Copy headers to an include directory:
make install
VTK should now be completely installed in the VTKBuild directory and ready to use in an XCode project!
Go to your finder, navigate to Users/you/VTK/Examples/GUI/Cocoa/ and double click to open SimpleCocoaVTK.xcodeproj in XCode.
In the XCode menubar (at the top of the screen) Go to Preferences->Locations->Source Trees and use the + button to add in two source trees:
vtk-debug-include vtk-debug-include Users/you/VTK/VTKBuild/include/vtk-6.1
vtk-debug-lib vtk-debug-lib Users/you/VTK/VTKBuild/lib
Click on the XCode project and delete all the references to vtk 6.0:
In the project view, select Targets->SimpleCocoaVTK and then press "Build Phases" and then open the "Link Binary With Libraries". Delete all the files that begin with "libvtk" and end with "6.0.a"
In the file view of the SimpleCocoaVTK project, hightlight and delete all the files in the vtk-libraries folder.
Make sure the XCode file view is active. Then in the finder, navigate to /Users/you/VTK/VTKBuild/lib, and select all the files that begin with "libvtk" and end with "6.1.a". Drag these files into the folder "vtk-libraries" in the XCode file view.
In XCode, do a Product->Clean
You can now build and run the sample SimpleCocoaVTK project.
I also had to set
VTK_WRAP_PYTHON:BOOL=ON
in CMakeCache.txt
It depends on what user you are too on your machine (computer) and the permissions relevant to that user. I did a find and replace on the CMakeCache.txt file and changed all /usr/local references to /Users/myusername/Develop/VTKInstall. That way everything's at your fingertips and you don't have to change permissions on things.
When you open up the Cocoa example make sure to set in you preferences these paths (e.g. Preferences->Locations->Source Trees). Also you'll need to re-import your vtk-libraries into the project.
I'm running Yosemite with XCode 6.1.1. I hope this helps someone!
If you get error messages likes this, when trying to build VTK:
#error: garbage collection is no longer supported
make[2]: *** Rendering/OpenGL/CMakeFiles/vtkRenderingOpenGL.dir/vtkCocoaRenderWindowInteractor.mm.o] Error 1
make1: *** [[Rendering/OpenGL/CMakeFiles/vtkRenderingOpenGL.dir/all] Error 2
You need to remove a flag in the source CMakeLists.txt:
#IF(APPLE)
SET(VTK_OBJCXX_FLAGS_DEFAULT "-fobjc-gc")
SET(VTK_REQUIRED_OBJCXX_FLAGS ${VTK_OBJCXX_FLAGS_DEFAULT} CACHE STRING "Extra flags for Objective-C++ compilation")
MARK_AS_ADVANCED(VTK_REQUIRED_OBJCXX_FLAGS)
ENDIF(APPLE)#
Either outcomment or delete it all together. Then run cmake again in an empty build directory. Check in the generated CMakeCache.txt in your build directory if it contains a key like VTK_REQUIRED_OBJCXX_FLAGS, it shouldn´t, try running cmake in an empty build directory again.
This 'bug' maybe fixed in future VTK versions.
Source: [Solved] Build Qt 5.2.1 + VTK 6.1.0 + CMake 2.8.12.2

Change the working directory in Xcode

I managed to get my C++ project running in Xcode using cmake -G Xcode. Now I would like to debug it, because of the nice gdb fronted it provides.
However I need to change the working directory where gdb is executed otherwise it wont work. (It needs to read some data from files relative to the path of the working directory) What I can do is after gdb has stopped typing cd working_dir and then run it manually typing r. This works, but Xcode will complain constantly and is also not an elegant solution.
So somewhere in the build settings I should be able to set the working directory..but where?!
Just updating this solution to XCode 4.x
You go on Product -> Scheme -> Edit Scheme
On the tab Options you choose your working directory.
In Xcode 4 the working directory settings is under Scheme Settings.
In Xcode 3.x do a "Get Info" on the executable and look at the first tab - there is a setting there for working directory.
The default debug working directory is somewhere under ~/Library/Developer/Xcode/DerivedData/project-/Build/Products/Debug. You're better off using the full path.

Resources