简体   繁体   English

如何从服务器上的 bash 脚本在虚拟环境中执行脚本?

[英]How to execute a script in a virtual environment from a bash script on server?

I am trying to run a python script in a virtual environment in a server using oarsub :我正在尝试使用 oarsub 在服务器的虚拟环境中运行 python 脚本:

So firstly I run this command in a server name "a" :因此,首先我在服务器名称 "a" 中运行此命令:

oarsub -l /host=1/gpu=1,walltime=2:00:00 './training_corpus1.sh'

training_corpus1.sh looks like this at the beguinning : training_corpus1.sh 在开始时看起来像这样:

#!/bin/bash

cd /home/ge/ke/anaconda3/envs

source activate env

cd ~/eXP/bert

CUDA_VISIBLE_DEVICES=0,1 python training.py \
    --exp_name bert \ ...

At the beguinning, I am suppose to open my virtual environment and then run the script but I am always getting this error in the OAR.18651.stderr file :在开始时,我想打开我的虚拟环境,然后运行脚本,但我总是在 OAR.18651.stderr 文件中收到此错误:


./training_corpus1.sh: line 5: activate: No such file or directory
Traceback (most recent call last):
  File "training.py", line 18, in <module>
    from xlm.slurm import init_signal_handler, init_distributed_mode
  File "/home/ge/ke/eXP/bert/xlm/slurm.py", line 11, in <module>
    import torch
ImportError: No module named torch


Torch is located in my virtual environment , it seems that It did not open.Whenusing "conda " a thte place of "source" I get: Torch 位于我的虚拟环境中,它似乎没有打开。当使用“conda”一个“源”的地方时,我得到:

./training_corpus1.sh: line 5: conda: command not found

For a virtual environment and bash the activation command is对于虚拟环境和bash ,激活命令是

source env/bin/activate

where env is the directory of the virtual environment to activate.其中env是要激活的虚拟环境的目录。

PS.附注。 Let me advice you to start any script with set -e to allow fast failing on any error:让我建议您使用set -e启动任何脚本,以允许在出现任何错误时快速失败:

#!/usr/bin/env bash
set -e
…

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 linux bash 脚本激活 python 虚拟环境 - Activcate a python virtual environment from a linux bash script 如何激活Python虚拟环境并同时执行脚本? - How to activate a Python virtual environment and execute a script at the same time? 如何从bash脚本中临时绕过python虚拟环境? - How can I temporary bypass python virtual environment from inside a bash script? 如何从 python 脚本激活虚拟环境并在其中执行进一步的指令? - How can I activate the virtual environment from a python script and execute further instructions while inside of it? 使用脚本从虚拟环境外部运行 DJango 服务器 - Run DJango server from outside of virtual environment by using script 如何在Mac上的bash脚本中激活Python虚拟环境并启动python脚本? - How can I activate a Python virtual environment and launch a python script, in a bash script on Mac? 在远程节点执行 bash 脚本并从服务器通过 python 控制 - Execute bash script at remote node and controlled via python from server 如何在没有cmd的虚拟环境中使用python运行python脚本 - How to run python script with python from virtual environment without cmd 从 python 脚本激活虚拟环境 - Activate virtual environment from a python script 从 py 脚本在虚拟环境中调用命令 - Calling command in virtual environment from py script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM