gopherdata / gophernotes

The Go kernel for Jupyter notebooks and nteract.
MIT License
3.83k stars 264 forks source link

Import third party not working even though in GOPATH #84

Closed raybuhr closed 6 years ago

raybuhr commented 6 years ago

Just downloaded and installed gophernotes on Ubuntu 16.04 and Go 1.9.1

I have the package dataframe installed from github.com/kniren/gotta/dataframe. I was able to start the gophernotes kernel successfully, but was unable to import any third party packages. I was able to use the text editor and terminal inside of jupyter to run code I was trying to run from the Go notebook, though.

Screenshot of gophernotes notebook:

notebook screenshot Code snippet that worked:

package main
​
import "fmt"
import "os"
import "github.com/kniren/gota/dataframe"
​
func main() {
    csvData, err := os.Open("test_data.csv")
    if err != nil {
        fmt.Println("could not open test_data.csv")
    }

    df := dataframe.ReadCSV(csvData)
    dfSummary := df.Describe()

    fmt.Println(df)
    fmt.Printf("%v", dfSummary)
}

Results of go run on that code

OS info if needed:


u0.2-noarch:security-9.20160110ubuntu0.2-amd64:security-9.20160110ubuntu0.2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial```
dwhitena commented 6 years ago

Thanks again for reporting this @raybuhr! Looking into it.

kortschak commented 6 years ago

The packages get installed into root's GOPATH, but are not built. I ran into this setting up a class prac that previously worked with the dwhitena/gophernotes, but now is borked.

As far as the terminal is concerned, GOPATH is not set, but it isn't in the Go notebook environment either (and they both believe that they are root), so I don't understand how they disagree on where to place files.

dwhitena commented 6 years ago

Yeah, this is somewhat interesting. The above import (and other 3rd party imports) work for me with the default GOPATH for my users (~/go), although there is another strange issue with gota that I'm investigating. @kortschak can you reproduce @raybuhr's issue above? If so, what is your GOPATH and environment?

kortschak commented 6 years ago

I should clarify that the gophernotes install I'm using in the case above is via docker. On that system GOPATH is unset. I will check on the non-docker install later today when I am able.

kortschak commented 6 years ago

This works for me with a non-docker gophernotes, but I'm not sure what @raybuhr's situation is. They say that they are on linux, but not whether this is a native install or a docker install.

dwhitena commented 6 years ago

@kortschak Yeah, I wouldn't expect the Docker install to work with third-party packages that aren't in the Docker image. There is a gophernotes-ds image with some common dependencies, but the default one is minimal. I should probably clarify this in the install docs.

Good to know they are working for you with the local install. You can either add them to the Docker install or maybe map a volume if you want to use your local dependencies (e.g., for your class).

kortschak commented 6 years ago

Yeah, I wouldn't expect the Docker install to work with third-party packages that aren't in the Docker image.

The things is that previously it did. The practical I wrote (https://github.com/kortschak/graphprac) was written to work with the dwhitena/gopernotes image (which we have installed on a suite of VMs for the class). I can't see any reason why it should not still work - I think it's a pretty serious limitation.

dwhitena commented 6 years ago

@kortschak Thanks for the other details. I'm guess why the Docker install worked for you before without explicitly including your imports, was that there was some magic going on under the hood with goimports and go list to get your dependencies. Typically, you would need to manually add your dependencies to the Docker image for other Go programs.

I suggest creating a Dockerfile similar to the following: https://github.com/gopherdata/gophernotes/blob/master/Dockerfile.DS, replacing the go get's under ## get the relevant Go packages with the imports you need. You can then build and use this Docker image and it should work as before. Happy to help with this here or on Gopher's Slack (@dwhitena) to get you back up and running. However, this is a slightly different topic than @raybuhr's original issue, so I will refrain from being too verbose here.

kortschak commented 6 years ago

No, I don't think that's it. The first step the students go through is to do go get github.com/kortschak/graphprac in a jupyter terminal. This does download the source, but it places it in /root/src, not in the GOPATH that it set up on the image. I remember doing some fooling around, details not in cache, but could not convince it to build the pkg in the correct locations.

dwhitena commented 6 years ago

Ahhhh... ok @kortschak. This makes more sense now. Thanks for clarifying. Yes, we should fix this. Thanks for opening issue https://github.com/gopherdata/gophernotes/issues/87, so we can continue working on @raybuhr's issue here.

raybuhr commented 6 years ago

To clarify, this issue was from my dedicated Ubuntu 16.04 install. I also tried installing from docker with a slightly modified version of the Dockerfile.DS in this repo. I was not able to import third-party in that environment either, but I also had other problems with the go installation so did not create an issue for that setup.

Just a reminder, I am able to install and use third-party packages in Go programs on this Ubuntu computer, just not from gophernotes. I also can't run the ipython magic commands from gophernotes, like ! echo $GOPATH , to try and verify what gophernotes is picking up. Lastly, the error message could be more helpful. For example, in my screenshot from the original issue posting, it just tells me it can't load the package and asks if I installed it. Typically Go import errors tell you what paths that looked in when they don't find it by name. I suggest keeping that behavior for easier debugging.

raybuhr commented 6 years ago

Update: I got everything working today so can close this issue

My fix was to uninstalled the gophernotes binary, pull the last version from github (only had a couple changes), reinstall, remove the gophernotes kernel and readd it. I had tried these steps previously before creating the issue and it didn't work, but I'm glad it is working now.