我正在使用多个命令行参数执行python脚本,但使用shell脚本。
执行shell脚本执行的命令是:
./scripts/run_qa.sh data/questions/questions.txt data/lexicons/paralex data/weights/paralex.txt data/database > output.txt
run_qa.sh文件如下所示(请解释它是如何工作的):
#!/bin/bash
set -u
set -e
if [ $# != 4 ]; then
echo "Usage: run.sh questions lexicon weights db"
exit 1
fi
questions=$1
lexicon=$2
weights=$3
db=$4
PYTHONPATH=$PWD/python python -m lex.gearman_worker $lexicon $weights $db < $questions
我尝试在命令行:
中执行如下的python命令python -m python/lex/gearman_worker.py data/lexicons/paralex data/weights/paralex.txt data/database > output.txt
给出错误:
/usr/bin/python: Import by filename is not supported.
Update1:
gearman_worker.py文件导入其他文件,如:
import lex.parse
import lex.semantics
from collections import namedtuple
from collections import defaultdict
import line会出现如下错误:
ImportError: No module named lex.lexicon
Update2(在linux终端上执行):
export PYTHONPATH=$/mnt/paralex-evaluation-gearman/python
PYTHONPATH = ./python python -m python/lex/gearman_worker data/lexicons/paralex data/weights/paralex.txt data/database > output.txt
给出:
PYTHONPATH: command not found
然后
python -m python/lex/gearman_worker data/lexicons/paralex data/weights/paralex.txt data/database > output.txt
给出:
File "/mnt/paralex-evaluation-gearman/python/lex/gearman_worker.py", line 3, in <module>
import lex.lexicon
ImportError: No module named lex.lexicon
答案 0 :(得分:0)
您只需执行以下命令:
PYTHONPATH=./python python -m lex.gearman_worker ARGUMENT_2 ARGUMENT_3 ARGUMENT_4 < ARGUMENT_1
如果这不起作用,那么您可能必须导出PYTHONPATH
设置:
export PYTHONPATH=${PWD}/python
python -m lex.gearman_worker ARGUMENT_2 ARGUMENT_3 ARGUMENT_4 < ARGUMENT_1
您传递给脚本的原始参数列为ARGUMENT_N
。
脚本只是:
您尝试调用它:
PYTHONPATH
设置