Linux环境下 代码java调用python出错

43 阅读1分钟

image.png @[TOC]

摘要

  1. 情况1:IOException: Cannot run program "python /temporary2/plus_non_main.py": error=2, No such file or directory
  2. 情况2:SyntaxError: Non-ASCII character '\xe6' in file /temporary2/plus_include_main.py on line 2, but no encoding declared; see www.python.org/peps/pep-02… for details

情况1:IOException: Cannot run program "python /temporary2/plus_non_main.py": error=2, No such file or directory

原因:python不认识

在这里插入图片描述

解决方法: 将python的执行改为绝对路径,也就是找到python.exe的所在位置

情况2:SyntaxError: Non-ASCII character '\xe6' in file /temporary2/plus_include_main.py on line 2, but no encoding declared; see www.python.org/peps/pep-02… for details

原因:py脚本定义的def函数中使用’’’注释快’’进行注释’’’

def plus2(a, b):
    '''# 有参数2-》网页方法3,试着传参数进去'''
    return (a + b)

解决方案:def定义的函数中使用“#单行注释”

image.png

重要信息

image.png

image.png

image.png