使用jsonrpc2的python Importerror

问题描述 投票:0回答:1

我正在尝试使用python的jsonrpc2。 我创建了一个文件hello.py

def greeting(name):
    return dict(message="Hello, %s!" % name)

然后我跑

runjsonrpc2 hello

但是我得到了

ImportError: No module named hello
python importerror json-rpc
1个回答
0
投票

看来runjsonrpc2无法在sys.path找到hello.py模块。

您可以仅设置PYTHONPATH环境变量来扩展搜索路径,包括hello模块所在的目录。

例如,如果您使用的是bash shell,则可以在hello.py文件的同一目录中运行以下命令:

$ export PYTHONPATH=$PYTHONPATH:.
$ runjsonrpc2 hello
© www.soinside.com 2019 - 2024. All rights reserved.