Why can't I deploy with 'goapp deploy' to GAE, I get can't find import: "github.com/go-sql-driver/mysql"

huangapple go评论109阅读模式
英文:

Why can't I deploy with 'goapp deploy' to GAE, I get can't find import: "github.com/go-sql-driver/mysql"

问题

主要问题:无法使用"goapp deploy"部署到GAE,一直收到以下消息:

src/mygoprog.go:11: 找不到导入: "github.com/go-sql-driver/mysql"

我已经成功部署了一个在端口8080上监听的“hello world”程序到GAE,现在尝试部署一个更复杂的程序。

在本地测试时这个是正常的:
C:\mysql\src>go run mygoprog.go

但是尝试部署到GAE时就不行了:
C:\mysql>goapp deploy

我已经重新安装了goappengine和go语言,并在卸载和安装之间清理了注册表。
任何帮助将不胜感激。

github安装命令:
goapp get github.com/go-sql-driver/mysql
也尝试过
go get github.com/go-sql-driver/mysql

源代码(我尝试过移动它,错误会跟随移动到第11行或第2行或其他位置):

import (
	"database/sql"
	"io/ioutil"
	"encoding/json"
	"fmt"
	"net/http"
	"log"
)
import	_ "github.com/go-sql-driver/mysql"

环境:
Python 2.7
Windows 7 - 64位
goappengine sdk版本1.9.1
mercurial 2.9.1

环境变量:
GOPATH=C:\mysql
GOROOT=C:\Go\

app.yml内容:
application: skilled-nation-521
version: 1
runtime: go
api_version: go1

处理程序:

  • url: /.*
    script: _go_app

这个不起作用:
C:\mysql>goapp deploy

    结果:
    05:20 PM 应用程序: skilled-nation-521; 版本: 1
    05:20 PM 主机: appengine.google.com
    05:20 PM
    正在更新应用程序: skilled-nation-521, 版本: 1
    05:20 PM 获取当前资源限制。
    05:20 PM 扫描本地磁盘上的文件。
    05:20 PM 克隆23个应用程序文件。
    05:20 PM 编译开始。
    05:20 PM 编译: 剩余16个文件。
    05:20 PM 错误422: --- 服务器输出开始 ---
    编译失败:
    2014/03/26 15:20:24 go-app-builder: build timing: 2├ù6g (171.487931ms total), 2├gopack (61.001119ms total), 0├ù6l (0 total)
    2014/03/26 15:20:24 go-app-builder: failed running 6g: exit status 1
    
    src/mygoprog.go:11: 找不到导入: "github.com/go-sql-driver/mysql"
    --- 服务器输出结束 ---
    05:20 PM 回滚更新。
    错误422: --- 服务器输出开始 ---

--- 服务器输出结束 ---
运行appcfg.py时出错: 退出状态1

c:\mysql的目录结构:

C:\mysql>dir
 C盘的卷没有标签。
 C盘的序列号是 D2E8-63AC

 C:\mysql 的目录

03/26/2014  05:14 PM    <DIR>          .
03/26/2014  05:14 PM    <DIR>          ..
03/25/2014  04:17 PM               119 app.yaml
03/26/2014  05:14 PM    <DIR>          pkg
03/26/2014  05:17 PM    <DIR>          src
               1 个文件            119 字节
               4 个目录 20,781,137,920 可用字节


C:\mysql>cd src

C:\mysql\src>dir
 C盘的卷没有标签。
 C盘的序列号是 D2E8-63AC

 C:\mysql\src 的目录

03/26/2014  05:17 PM    <DIR>          .
03/26/2014  05:17 PM    <DIR>          ..
03/26/2014  05:14 PM    <DIR>          github.com
03/26/2014  05:14 PM             2,666 mygoprog.go
               1 个文件          2,666 字节
               3 个目录 20,781,387,776 可用字节

C:\mysql\src>cd github.com

C:\mysql\src\github.com>dir
 C盘的卷没有标签。
 C盘的序列号是 D2E8-63AC

 C:\mysql\src\github.com 的目录

03/26/2014  05:14 PM    <DIR>          .
03/26/2014  05:14 PM    <DIR>          ..
03/26/2014  05:14 PM    <DIR>          go-sql-driver
               0 个文件              0 字节
               3 个目录 20,781,387,776 可用字节
英文:

Main problem: can't deploy with 'goapp deploy' to GAE, keep getting this message:

src/mygoprog.go:11: can't find import: "github.com/go-sql-driver/mysql"

I have deployed 'hello world' program that listens on port 8080 to GAE with no problems; now trying to deploy a more sophisticated program.

This works just fine to test locally:
C:\mysql\src>go run mygoprog.go

This does not when trying to deploy to GAE:
C:\mysql>goapp deploy

I've reinstalled goappengine and go language from scratch with cleaned up registry between uninstall and install.
Any help would be appreciated.

github install command(s):
goapp get github.com/go-sql-driver/mysql
also tried
go get github.com/go-sql-driver/mysql

Source code (I've tried moving it around, the error follows the move to line 11 or 2 or whatever):

import (
	&quot;database/sql&quot;
	&quot;io/ioutil&quot;
	&quot;encoding/json&quot;
	&quot;fmt&quot;
	&quot;net/http&quot;
	&quot;log&quot;
)
import	_ &quot;github.com/go-sql-driver/mysql&quot;

Environment:
Python 2.7
Windows 7 - 64 bit
goappengine sdk version 1.9.1
mercurial 2.9.1

Environment variables:
GOPATH=C:\mysql
GOROOT=C:\Go\

app.yml contents:
application: skilled-nation-521
version: 1
runtime: go
api_version: go1

handlers:

  • url: /.*
    script: _go_app
This does not work:
C:\mysql&gt;goapp deploy

    Results:
    05:20 PM Application: skilled-nation-521; version: 1
    05:20 PM Host: appengine.google.com
    05:20 PM
    Starting update of app: skilled-nation-521, version: 1
    05:20 PM Getting current resource limits.
    05:20 PM Scanning files on local disk.
    05:20 PM Cloning 23 application files.
    05:20 PM Compilation starting.
    05:20 PM Compilation: 16 files left.
    05:20 PM Error 422: --- begin server output ---
    Compile failed:
    2014/03/26 15:20:24 go-app-builder: build timing: 2├&#249;6g (171.487931ms total), 2├gopack (61.001119ms total), 0├&#249;6l (0 total)
    2014/03/26 15:20:24 go-app-builder: failed running 6g: exit status 1
    
   

    src/mygoprog.go:11: can&#39;t find import: &quot;github.com/go-sql-driver/mysql&quot;
    --- end server output ---
    05:20 PM Rolling back the update.
    Error 422: --- begin server output ---

--- end server output ---
error while running appcfg.py: exit status 1

Directory structure of c:\mysql:

C:\mysql&gt;dir
 Volume in drive C is OS
 Volume Serial Number is D2E8-63AC

 Directory of C:\mysql

03/26/2014  05:14 PM    &lt;DIR&gt;          .
03/26/2014  05:14 PM    &lt;DIR&gt;          ..
03/25/2014  04:17 PM               119 app.yaml
03/26/2014  05:14 PM    &lt;DIR&gt;          pkg
03/26/2014  05:17 PM    &lt;DIR&gt;          src
               1 File(s)            119 bytes
               4 Dir(s)  20,781,137,920 bytes 


C:\mysql&gt;cd src

C:\mysql\src&gt;dir
 Volume in drive C is OS
 Volume Serial Number is D2E8-63AC

 Directory of C:\mysql\src

03/26/2014  05:17 PM    &lt;DIR&gt;          .
03/26/2014  05:17 PM    &lt;DIR&gt;          ..
03/26/2014  05:14 PM    &lt;DIR&gt;          github.com
03/26/2014  05:14 PM             2,666 mygoprog.go
               1 File(s)          2,666 bytes
               3 Dir(s)  20,781,387,776 bytes free

C:\mysql\src&gt;cd github.com

C:\mysql\src\github.com&gt;dir
 Volume in drive C is OS
 Volume Serial Number is D2E8-63AC

 Directory of C:\mysql\src\github.com

03/26/2014  05:14 PM    &lt;DIR&gt;          .
03/26/2014  05:14 PM    &lt;DIR&gt;          ..
03/26/2014  05:14 PM    &lt;DIR&gt;          go-sql-driver
               0 File(s)              0 bytes
               3 Dir(s)  20,781,387,776 bytes free








</details>


# 答案1
**得分**: 1

导入路径必须从包含 app.yaml 文件的文件夹中起作用。所以你需要将 github.com 文件夹移动到那里。(类似问题:https://stackoverflow.com/questions/7989799/how-to-import-local-golang-package-in-gae)

注意:你不应该使用 go 可执行文件来测试你的 App Engine 代码,应该始终使用 goapp 工具。

<details>
<summary>英文:</summary>

The import path must work from the folder where the app.yaml resides. So you need to move the github.com folder up there. (Similar question: https://stackoverflow.com/questions/7989799/how-to-import-local-golang-package-in-gae)

Note: You should never test your App Engine stuff with the go executable, always use the goapp tool.

</details>



huangapple
  • 本文由 发表于 2014年3月27日 06:47:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/22674661.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定