Python 3.x 将路径变量从powershell x86传递到python不会';行不通
我经常使用Windows PowerShell运行python脚本。我最近对代码进行了更改,但现在似乎不起作用。 更详细地说,从powershell传递到python的变量“root\u dir\u path”存在一个问题 在powershell中,我运行以下命令,该命令应定义路径变量“root\u dir\u path”:Python 3.x 将路径变量从powershell x86传递到python不会';行不通,python-3.x,powershell,powershell-2.0,Python 3.x,Powershell,Powershell 2.0,我经常使用Windows PowerShell运行python脚本。我最近对代码进行了更改,但现在似乎不起作用。 更详细地说,从powershell传递到python的变量“root\u dir\u path”存在一个问题 在powershell中,我运行以下命令,该命令应定义路径变量“root\u dir\u path”: PS Z:\> C:\Hyapp\FIJI-W~1.52P\Fiji.app\ImageJ-win64.exe --ij2 --headless -- consol
PS Z:\> C:\Hyapp\FIJI-W~1.52P\Fiji.app\ImageJ-win64.exe --ij2 --headless --
console --run D:\Cabut-
PWP1-preliminary-data\All\great_grandpa\stitcher-GREAT-grandpa-pro-2.0.py
"root_dir_path='D:\Cabut-
PWP1-preliminary-data\All\Stitching'"
有人能告诉我为什么它不起作用吗
特别是给出以下错误:
NameError: name 'root_dir_path' is not defined
当我试图调用main()函数时,有问题的一行(361):
main(root_dir_path)
我在powershell中获得以下信息:
PS Z:\> C:\Hyapp\FIJI-W~1.52P\Fiji.app\ImageJ-win64.exe --ij2 --headless --console --run D:\Cabut-
PWP1-preliminary-data\All\great_grandpa\stitcher-GREAT-grandpa-pro-2.0.py "root_dir_path='D:\Cabut-
PWP1-preliminary-data\All\Stitching'"
PS Z:\> Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed
in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be
removed in a future release
tammikuuta 31, 2020 5:21:04 IP. java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows
RegCreateKeyEx(...) returned error code 5.
[WARNING] Unmatched input: root_dir_path
[ERROR] Traceback (most recent call last):
File "D:\Cabut-PWP1-preliminary-data\All\great_grandpa\stitcher-GREAT-grandpa-pro-2.0.py", line 362,
in <module>
main(root_dir_path)
NameError: name 'root_dir_path' is not defined
at org.python.core.Py.NameError(Py.java:290)
at org.python.core.PyFrame.getname(PyFrame.java:257)
at org.python.pycode._pyx0.f$0(D:\Cabut-PWP1-preliminary-data\All\great_grandpa\stitcher-GREAT-grandpa-pro-2.0.py:362)
at org.python.pycode._pyx0.call_function(D:\Cabut-PWP1-preliminary-data\All\great_grandpa\stitcher-GREAT-grandpa-pro-2.0.py)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at org.python.core.__builtin__.eval(__builtin__.java:497)
at org.python.core.__builtin__.eval(__builtin__.java:501)
at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
PS Z:\>C:\Hyapp\FIJI-W~1.52P\FIJI.app\ImageJ-win64.exe--ij2--headless--console--run D:\Cabut-
PWP1初步数据\All\great\u-grandpa\stitchr-great-grandpa-pro-2.0.py“root\u dir\u path='D:\Cabut-
PWP1初步数据\全部\缝合''
PS Z:\>Java HotSpot(TM)64位服务器虚拟机警告:忽略选项PermSize=128m;支架被拆除
在8.0中
Java HotSpot(TM)64位服务器VM警告:不推荐使用增量CMS,可能会
在将来的版本中删除
tammikuuta 3120205:21:04 IP。java.util.prefs.WindowsPreferences
警告:无法在根0x8000002处打开/创建prefs根节点Software\JavaSoft\prefs。窗户
RegCreateKeyEx(…)返回错误代码5。
[警告]输入不匹配:根目录路径
[错误]回溯(最近一次呼叫上次):
文件“D:\Cabut-PWP1-premidial-data\All\great\u-grandpa\stitchr-great-grandpa-pro-2.0.py”,第362行,
在里面
主(根目录路径)
名称错误:未定义名称“根目录路径”
位于org.python.core.Py.NameError(Py.java:290)
位于org.python.core.PyFrame.getname(PyFrame.java:257)
在org.python.pycode.\u pyx0.f$0(D:\Cabut-PWP1-premial-data\All\great\u-grandpa\stitcher-great-grandpa-pro-2.0.py:362)
在org.python.pycode.\u pyx0.call\u函数(D:\Cabut-PWP1-premial-data\All\great\u-grandpa\stitcher-great-grandpa-pro-2.0.py)
位于org.python.core.PyTableCode.call(PyTableCode.java:171)
位于org.python.core.PyCode.call(PyCode.java:18)
位于org.python.core.Py.runCode(Py.java:1614)
在org.python.core.\uuuuu-builtin\uuuuu.eval(\uuuu-builtin\uuuuu.java:497)
在org.python.core.\uuuuu-builtin\uuuuu.eval(\uuuuu-builtin\uuuu.java:501)
位于org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
位于org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
位于org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
位于javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
运行(ScriptModule.java:160)
运行(ModuleRunner.java:168)
调用(ModuleRunner.java:127)
调用(ModuleRunner.java:66)
位于org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
在java.util.concurrent.FutureTask.run(FutureTask.java:266)处
位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
运行(Thread.java:748)
我终于明白了
python脚本中对main函数的调用也包含以下内容:
#@String root_dir_path
main(root_dir_path)
此#@String root_dir_path
似乎是变量从powershell正确传递所必需的。当我在pycharm中自动重新格式化时,添加了一个空格,因为它认为这行是一条简单的注释:
# @String root_dir_path
这似乎是导致错误的原因。去掉空间后,它又可以工作了。我终于明白了 python脚本中对main函数的调用也包含以下内容:
#@String root_dir_path
main(root_dir_path)
此#@String root_dir_path
似乎是变量从powershell正确传递所必需的。当我在pycharm中自动重新格式化时,添加了一个空格,因为它认为这行是一条简单的注释:
# @String root_dir_path
这似乎是导致错误的原因。清除空间后,它可以再次工作