自动秒收录

使用conda工具安装软件包的命令是 (使用conda的环境 java调python文件)


文章编号:618 / 更新时间:2023-11-08 14:20:45 / 浏览:
Windows


  • windows环境

解决:

  1. 编写activate.cmd
:: windows切换环境
activate gdal3.3.1
  1. java调用脚本
// 先切换环境再执行脚本
String cmd = "D:\\ars\\m2m\\activate.cmd && " ;   // 切换环境
      += " python D:\\ars\\m2m\\tvdi.py" ;    // 执行脚本
      += " --LC08_fn --shape_fn" ;        // 传递参数
logger.info("-------------------> " + cmd + " <-------------------");
// 执行
Process p = Runtime.getRuntime().exec(cmd);
String read, result = "";
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream(), "gbk"));
while ((read = in .readLine()) != null) {
    result += read;
p.waitFor();
// 返回结果
logger.info("-------------------> " + result + " <-------------------");
  • linux环境
# 查找
whereis conda
# 查找
which python
> /root/miniconda3/envs/mmenv/bin/python
  • 全路径执行
@Test
void testDk() throws IOException, InterruptedException {
    String cmd = "/root/miniconda3/envs/mmenv/bin/python ~/0predict1.py";
    Process p = Runtime.getRuntime().exec(cmd);
    String read, result = "";
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream(), "gbk"));
    while ((read = in.readLine()) != null) {
        result += read;
    p.waitFor();
    logger.info("-------------------> result: " + result + " <-------------------");



相关标签: WindowsJavaPythonLinux

本文地址:https://www.0558.la/article/433784cd9475d5666a89.html

上一篇:bundle是什么意思bundlergt230versionError...
下一篇:新注册的域名多久可以备案新注册的域名要如...

温馨提示

做上本站友情链接,在您站上点击一次,即可自动收录并自动排在本站第一位!
<a href="https://www.0558.la/" target="_blank">自动秒收录</a>