如何在Heroku上使用Python使Zxing正常工作?

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

How to get Zxing in python working with Heroku?

问题

我正在将Python Flask应用部署到Heroku上,该应用使用Zxing来读取二维码并提取其中的数据,但是Zxing在Heroku环境中需要Java支持。

Zxing:https://github.com/dlenski/python-zxing

关于Zxing的错误

barcode = reader.decode(f) #qrreader.data#
File "/app/.heroku/python/lib/python3.6/site-packages/zxing/__init__.py", line 48, in decode
raise BarCodeReaderException("Java binary specified does not exist", self.java, e)
zxing.BarCodeReaderException: ('Java binary specified does not exist', 'java', FileNotFoundError(2, "No such file or directory: 'java'"))

我尝试过的方法

我已经将Java Buildpack添加到环境中,与Python一起使用,但这会引发错误,而且我不确定它是否会解决问题。

Heroku的Java Buildpack:

heroku/java

我还寻找了其他可以只使用Python执行相同任务的库(但没有找到合适的,zbar有依赖问题)。

我的当前构建包

https://github.com/survantjames/heroku-buildpack-poppler.git
heroku/python
https://github.com/heroku/heroku-buildpack-apt

所有这些在本地Windows 10环境中都能正常工作,因为Java已安装,没有其他更改。

是否有办法使Zxing工作或是否有其他可行的替代方法?

谢谢:D

编辑: Java构建错误详细信息(不相关,请查看下面的答案)

重写 package-config 文件
remote: -----> 检测到JVM公共应用
remote: -----> 安装JDK 1.8...完成
remote: -----> 检测到Java应用
remote: -----> 使用提供的JDK
remote: -----> 安装Maven 3.6.2...完成
remote: -----> 执行Maven
remote:        $ mvn -DskipTests clean dependency:list install
remote:        [INFO] 正在扫描项目...
remote:        [ERROR] [ERROR] 在处理POM时出现了一些问题
remote:        [ERROR] 'modelVersion' 丢失@ 第1行第9列
remote:        [FATAL] 'groupId' 丢失@ 第1行第9列
remote:        [FATAL] 'artifactId' 丢失@ 第1行第9列
remote:        [FATAL] 'version' 丢失@ 第1行第9列
remote:         @
remote:        [ERROR] 无法读取1个项目 -> [帮助 1]
remote:        [ERROR]
remote:        [ERROR] 项目[unknown-group-id]:[unknown-artifact-id]:[unknown-version] (/tmp/build_7e2d7b50/pom.xml)存在4个错误
remote:        [ERROR] 'modelVersion' 丢失@ 第1行第9列
remote:        [ERROR] 'groupId' 丢失@ 第1行第9列
remote:        [ERROR] 'artifactId' 丢失@ 第1行第9列
remote:        [ERROR] 'version' 丢失@ 第1行第9列
remote:        [ERROR]
remote:        [ERROR] 要查看错误的完整堆栈跟踪请使用-e开关重新运行Maven
remote:        [ERROR] 使用-X开关重新运行Maven以启用完整的调试日志记录
remote:        [ERROR]
remote:        [ERROR] 有关错误和可能解决方案的更多信息请阅读以下文章
remote:        [ERROR] [帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
remote:
remote:  !     错误使用Maven构建应用程序失败
remote:        很抱歉此构建失败了如果在应用程序代码中找不到问题
remote:        请提交工单以便我们提供帮助https://help.heroku.com/
remote:
remote:  !     推送被拒绝无法编译Java应用
remote:
remote:  !     推送失败无法推送到invoice-parser

英文:

I am deploying a python flask app to heroku which uses Zxing to read qr codes(scan them) and give out the data on them, however Zxing requires Java on the heroku environment.

Zxing : https://github.com/dlenski/python-zxing

Error with Zxing

barcode = reader.decode(f) #qrreader.data#
File "/app/.heroku/python/lib/python3.6/site-packages/zxing/__init__.py", line 48, in decode
raise BarCodeReaderException("Java binary specified does not exist", self.java, e)
zxing.BarCodeReaderException: ('Java binary specified does not exist', 'java', FileNotFoundError(2, "No such file or directory: 'java'"))

What I have Tried

Added the java buildpack to the environment along side python but that spits out an error and i am not sure if it would solve the problem either way.

the Java buildpack from heroku

heroku/java

Looked for other libraries that can do the same job with only python(found none)(zbar dependency issues)

My current build packs

https://github.com/survantjames/heroku-buildpack-poppler.git
heroku/python
https://github.com/heroku/heroku-buildpack-apt

All of this works on a local windows 10 environment with java installed and no other changes.

Is there a way to get Zxing working or is there an alternative that will work?

Thanks:D

EDIT:
Java Build error details.(irrelevant, check below answer)

Rewrite package-config files
remote: -----> JVM Common app detected
remote: -----> Installing JDK 1.8... done
remote: -----> Java app detected
remote: -----> Using provided JDK
remote: -----> Installing Maven 3.6.2... done
remote: -----> Executing Maven
remote:        $ mvn -DskipTests clean dependency:list install
remote:        [INFO] Scanning for projects...
remote:        [ERROR] [ERROR] Some problems were encountered while processing the POMs:
remote:        [ERROR] 'modelVersion' is missing. @ line 1, column 9
remote:        [FATAL] 'groupId' is missing. @ line 1, column 9
remote:        [FATAL] 'artifactId' is missing. @ line 1, column 9
remote:        [FATAL] 'version' is missing. @ line 1, column 9
remote:         @
remote:        [ERROR] The build could not read 1 project -> [Help 1]
remote:        [ERROR]
remote:        [ERROR]   The project [unknown-group-id]:[unknown-artifact-id]:[unknown-version] (/tmp/build_7e2d7b50/pom.xml) has 4 errors
remote:        [ERROR]     'modelVersion' is missing. @ line 1, column 9
remote:        [ERROR]     'groupId' is missing. @ line 1, column 9
remote:        [ERROR]     'artifactId' is missing. @ line 1, column 9
remote:        [ERROR]     'version' is missing. @ line 1, column 9
remote:        [ERROR]
remote:        [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
remote:        [ERROR] Re-run Maven using the -X switch to enable full debug logging.
remote:        [ERROR]
remote:        [ERROR] For more information about the errors and possible solutions, please read the following articles:
remote:        [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
remote:
remote:  !     ERROR: Failed to build app with Maven
remote:        We're sorry this build is failing! If you can't find the issue in application code,
remote:        please submit a ticket so we can help: https://help.heroku.com/
remote:
remote:  !     Push rejected, failed to compile Java app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to invoice-parser.

答案1

得分: 2

我已经成功解决了我的错误,通过将构建包

https://github.com/heroku/heroku-buildpack-jvm-common.git

代替了Heroku提供的Java构建包(编辑: heroku/java),我使用的构建包只是将JVM安装到我的环境中,***编辑:***这也是由Heroku提供的,并在链接中提到。

现在Zxing构建正常 如何在Heroku上使用Python使Zxing正常工作?

***编辑:***由于我的糟糕写作导致了混淆,但我绝对不是指Heroku不提供这些构建包。我在这里说“代替”应该在问题的上下文中理解,因此它代替了原始的构建包(heroku/java)。它绝不表示Heroku不提供这些构建包。

感谢指出混淆。

英文:

I have managed to solve my error by adding the buildpack

https://github.com/heroku/heroku-buildpack-jvm-common.git

in place of the java buildpack( EDIT: heroku/java) heroku provides, the buildpack i have used just installs jvm to my environment EDIT: which is also provided by heroku and is mentioned in link.

Zxing now builds fine 如何在Heroku上使用Python使Zxing正常工作?

EDIT: There was confusion due to bad writing on my part but i do not at all mean that heroku does not provide these buildpacks. Me saying "in place" here shoud be taken in context of the question and as such it is in place of the original buildpack(heroku/java). It in no place or form means that heroku does not provide the buildpacks.

Thanks for pointing out the confusion

huangapple
  • 本文由 发表于 2020年8月9日 18:01:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63324973.html
匿名

发表评论

匿名网友

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

确定