[英]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.