问题
I am trying to deploy my first Plotly Dash app (written in Python) to Heroku. I am having trouble with bundling up all the packages to compile the app, currently with Python-javabridge.
When I try to deploy my app, even after deleting python-javabridge from the requirements.txt
, it still tries to bundle it, giving me the following error:
remote: Collecting jeepney>=0.4.2; sys_platform == "linux"
remote: Downloading jeepney-0.6.0-py3-none-any.whl (45 kB)
remote: Collecting importlib-resources; python_version < "3.7"
remote: Downloading importlib_resources-4.1.1-py3-none-any.whl (22 kB)
remote: Collecting python-javabridge==4.0.0
remote: Downloading python-javabridge-4.0.0.tar.gz (1.3 MB)
remote: ERROR: Command errored out with exit status 1:
remote: command: /app/.heroku/python/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qllzoihk/python-javabridge/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qllzoihk/python-javabridge/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-xeh4coov
remote: cwd: /tmp/pip-install-qllzoihk/python-javabridge/
remote: Complete output (11 lines):
remote: Traceback (most recent call last):
remote: File "<string>", line 1, in <module>
remote: File "/tmp/pip-install-qllzoihk/python-javabridge/setup.py", line 412, in <module>
remote: ext_modules=ext_modules(),
remote: File "/tmp/pip-install-qllzoihk/python-javabridge/setup.py", line 96, in ext_modules
remote: java_home = find_javahome()
remote: File "/tmp/pip-install-qllzoihk/python-javabridge/javabridge/locate.py", line 133,
in find_javahome
remote: java_bin = get_out(["bash", "-c", "type -p java"])
remote: File "/tmp/pip-install-qllzoihk/python-javabridge/javabridge/locate.py", line 130,
in get_out
remote: raise Exception("Error finding javahome on linux: %s" % cmd)
remote: Exception: Error finding javahome on linux: ['bash', '-c', 'type -p java']
remote: ----------------------------------------
remote: ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
What I have done:
Just running pip install javabridge
works perfectly, no problems.
I added JAVA_HOME
to my system variables and to path, didn't help. Writing javac
or java --version
on the cmd outputs the version as expected.
I use Windows 10, Python 3.7, Anaconda3, Spyder terminal to run the commands.
回答1:
If you want to use Java from a Python application on Heroku you'll need to use multiple buildpacks. Note that
The buildpack for the primary language of your app should always be the last buildpack in the list. This ensures that defaults for that primary language are applied instead of those for another language, and allows Heroku to correctly detect the primary language of your app.
So in this case, do something like
PS C:\> heroku buildpacks:set heroku/python
PS C:\> heroku buildpacks:add --index 1 heroku/jvm
If you run heroku buildpacks
you should now see the JVM buildpack listed first and the Python buildpack listed second. Note that we are using heroku/jvm
here, not heroku/java
, since you aren't building a Java application.
After doing this you'll need to redeploy your application. If you have changes to make, go ahead and make them, then commit, and push.
Note that your application might need to use the Java bridge even if you aren't directly depending on it in your requirements.txt
, e.g. if one of your dependencies depends on it.
来源:https://stackoverflow.com/questions/65594909/heroku-fails-to-bundle-python-javabridge-javahome-not-found