我正在尝试在Apache上的浏览器中执行Julia代码(我在Windows 10上使用Ampps)。我能够执行它真正的命令提示符或通过python代码调用它(请参阅下面的python代码)。当我尝试直接在浏览器上执行Julia代码时,我得到网关超时服务器没有及时响应消息。但是当我尝试执行调用Julia代码的python代码时,我会在Apache的错误日志中获得更详细的信息:
fatal: error thrown and no exception handler available.:C:/Program Files
(x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
rec_backtrace at /home/Administrator/buildbot/slave/package_win6_2-x64/build
/src/home/Administrator/buildbot/slave/package_win6_2-x64/build/src\\stackwalk.c:84:
C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer:
http://localhost/csvToLayer_JSAPI/
record_backtrace at /home/Administrator/buildbot/slave/package_win6_2-x64/build/src/home
/Administrator/buildbot/slave/package_win6_2-x64/build/src\\task.c:233:
C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py,
referer: http://localhost/csvToLayer_JSAPI/
jl_throw at /home/Administrator/buildbot/slave/package_win6_2-x64/build/src/home/Administrator/buildbot/slave/package_win6_2-x64/build/src\\task.c:551:
C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
access_env at .\\env.jl:14: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py,referer:
http://localhost/csvToLayer_JSAPI/
homedir at .\\path.jl:41: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer:
http://localhost/csvToLayer_JSAPI/
_pkgroot at .\\pkg\\dir.jl:10 [inlined]: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py,
referer: http://localhost/csvToLayer_JSAPI/
__init__ at .\\pkg\\pkg.jl:74: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py,
referer: http://localhost/csvToLayer_JSAPI/
unknown function (ip: 0000000061D151DE): C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py,
referer: http://localhost/csvToLayer_JSAPI/
jl_call_method_internal at /home/Administrator/buildbot/slave
/package_win6_2-x64/build/src/home/Administrator/buildbot/slave/package_win6_2-x64/build/src\\julia_internal.h:210 [inlined]:
C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
jl_apply_generic at /home/Administrator/buildbot/slave/package_win6_2-x64/build/src/home/Administrator/buildbot/slave/package_win6_2-x64/build/src\\gf.c:1950: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
jl_apply at /home/Administrator/buildbot/slave/package_win6_2-x64/build/src/home/Administrator/buildbot/slave/package_win6_2-x64/build/src\\julia.h:1392 [inlined]:
C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py,
referer: http://localhost/csvToLayer_JSAPI/
jl_module_run_initializer at /home/Administrator/buildbot/slave/package_win6_2-x64/build/src/home/Administrator/buildbot/slave/package_win6_2-x64/build/src\\toplevel.c:83: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
_julia_init at /home/Administrator/buildbot/slave/package_win6_2-x64/build/src/home/Administrator/buildbot/slave/package_win6_2-x64/build/src\\init.c:742:
C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer:
http://localhost/csvToLayer_JSAPI/
julia_init at /home/Administrator/buildbot/slave/package_win6_2-x64/build/src/home/Administrator/buildbot/slave/package_win6_2-x64/build/src\\task.c:284: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
wmain at /home/Administrator/buildbot/slave/package_win6_2-x64/build/ui\\repl.c:242: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
__tmainCRTStartup at /usr/src/debug/mingw64-x86_64-runtime-4.0.6-1/crt\\crtexe.c:329: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
mainCRTStartup at /usr/src/debug/mingw64-x86_64-runtime-4.0.6-1/crt\\crtexe.c:212: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
BaseThreadInitThunk at C:\\WINDOWS\\System32\\KERNEL32.DLL (unknown line): C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
RtlUserThreadStart at C:\\WINDOWS\\SYSTEM32\\ntdll.dll (unknown line): C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
Base.InitError(mod=:Pkg, error=Base.KeyError(key="HOMEDRIVE")): C:/Program Files (x86)/
Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
Traceback (most recent call last):\r: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
File "C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py", line 20, in
<module>\r: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer:
http://localhost/csvToLayer_JSAPI/
x = subprocess.check_output(cmd)\r: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer:
http://localhost/csvToLayer_JSAPI/
File "C:\\Python27\\ArcGIS10.3\\lib\\subprocess.py", line 573, in check_output\r:
C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
raise CalledProcessError(retcode, cmd, output=output)\r: C:/Program Files (x86)/
Ampps/www/csvToLayer_JSAPI/python.py, referer: http://localhost/csvToLayer_JSAPI/
subprocess.CalledProcessError: Command '['C:/Users/Reza/AppData/Local/Julia-0.5.1/bin/julia.exe',
'C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/HT.jl']' returned non-zero exit status
-1073741510\r: C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/python.py,
referer: http://localhost/csvToLayer_JSAPI/
这似乎是一个与如何在Julia中设置APPDATA env变量相关的已知问题。 Here,建议应在httpd.conf或httpd-vhosts.conf中设置HOMEDRIVE,HOMEPATH和APPDATA的env变量。我试过编辑httpd-vhosts.conf和httpd.conf,但我仍然得到同样的错误。
这就是我编辑httpd.conf的方式:
#### Localhost VirtualHost ####
<VirtualHost 127.0.0.1:80>
<Directory "{$path}/www">
Options Indexes FollowSymLinks ExecCGI
AddHandler cgi-script .cgi .py .jl
AllowOverride All
Order deny,allow
allow from All
</Directory>
SetEnv HOMEDRIVE "C:"
SetEnv HOMEPATH "/Users/Reza"
SetEnv APPDATA "C:/Users/Reza/AppData/Roaming"
ScriptLog logs/julia_cgi.log
ServerName localhost
ServerAlias localhost 127.0.0.1
ScriptAlias /cgi-bin/ "{$path}/www/cgi-bin/"
DocumentRoot "{$path}/www"
ErrorLog "{$path}/apache/logs/error.log"
CustomLog "{$path}/apache/logs/access.log" combined
</VirtualHost>
这是调用Julia代码的python代码:
#!"C:/Python27/ArcGIS10.3/python.exe"
import subprocess
print "Content-Type: text/html\n\n"
print "hi there! this is python!"
command="C:/Users/Reza/AppData/Local/Julia-0.5.1/bin/julia.exe"
path2script="C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/HT.jl"
cmd = [command, path2script]
x = subprocess.check_output(cmd)
print x
这是朱莉娅代码:
#!"C:/Users/Reza/AppData/Local/Julia-0.5.1/bin/julia.exe"
redirect_stderr(STDOUT)
println("Content-Type: text/html\n\n")
println("hi there; this is Julia!");
println("Julia is passing outputs to Python");
我是否为APPDATA env变量设置了一个wroge位置?我应该为APPDATA使用什么文件夹?除了“C:/ Users / Reza / AppDate / Roaming”之外,我还尝试了“C:/ Users / Reza / AppDate / Local”和“C:/Users/Reza/AppDate/Local/Julia-0.5.1” ,我得到同样的错误。
答案 0 :(得分:1)
我不知道为什么SetEnv在httpd.conf中不起作用,但我找到了一个解决方法。我在Python中设置了环境变量:
#!"C:/Python27/ArcGIS10.3/python.exe"
import subprocess,os
print "Content-Type: text/html\n\n"
print "hi there! this is python!"
os.environ["HOMEDRIVE"]="C:"
os.environ["HOMEPATH"]="/Users/Reza"
os.environ["APPDATA"]="C:/Users/Reza/AppData/Roaming"
command="C:/Users/Reza/AppData/Local/Julia-0.5.1/bin/julia.exe"
path2script="C:/Program Files (x86)/Ampps/www/csvToLayer_JSAPI/HT.jl"
cmd = [command, path2script]
try:
print subprocess.check_output(cmd)
except subprocess.CalledProcessError as e:
print e.output