Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在GCP可抢占虚拟机上的启动脚本中运行conda命令_Python_Bash_Google Cloud Platform_Anaconda - Fatal编程技术网

Python 在GCP可抢占虚拟机上的启动脚本中运行conda命令

Python 在GCP可抢占虚拟机上的启动脚本中运行conda命令,python,bash,google-cloud-platform,anaconda,Python,Bash,Google Cloud Platform,Anaconda,我正在一个可抢占的谷歌虚拟机上运行一个深度学习模型。我正在使用anaconda和TensorFlow来运行我的代码。当我ssh到机器中并手动运行python脚本时,它工作得很好。考虑到机器是可抢占的,我创建了一个云调度器,如果每15分钟抢占一次,它就可以启动实例。现在,我正在编写一个启动脚本,以从终止点恢复模型 我安装了anaconda,以便在名为tf的conda环境中,所有用户和tensorflow都可以访问它。 这是我的启动脚本 #! /bin/bash sudo -u subhashner

我正在一个可抢占的谷歌虚拟机上运行一个深度学习模型。我正在使用anaconda和TensorFlow来运行我的代码。当我ssh到机器中并手动运行python脚本时,它工作得很好。考虑到机器是可抢占的,我创建了一个云调度器,如果每15分钟抢占一次,它就可以启动实例。现在,我正在编写一个启动脚本,以从终止点恢复模型

我安装了anaconda,以便在名为tf的conda环境中,所有用户和tensorflow都可以访问它。 这是我的启动脚本

#! /bin/bash
sudo -u subhashnerella bash -c 'cd ~/Project;. ./startup.sh'
运行位于用户“subhashnerella”主页/项目中的startup.sh

内部startup.sh

#! /bin/bash
eval "$(conda shell.bash hook)"
conda activate tf
python start.py
在这里,我激活了conda环境并运行start.py来训练我的模型

测试启动脚本时出现的错误

(base) subhashnerella@instance-1:~$ sudo google_metadata_script_runner --script-type startup --debug
startup-script: INFO Starting startup scripts.
startup-script: INFO Found startup-script in metadata.
startup-script: INFO startup-script: ./startup.sh: line 2: conda: command not found
startup-script: INFO startup-script: ./startup.sh: line 2: $'\r': command not found
startup-script: INFO startup-script: ./startup.sh: line 3: conda: command not found
startup-script: INFO startup-script: ./startup.sh: line 4: python: command not found
startup-script: INFO startup-script: ./startup.sh: line 5: $'\r': command not found
startup-script: INFO startup-script: ./startup.sh: line 6: $'\r': command not found
startup-script: INFO startup-script: Return code 127.
startup-script: INFO Finished running startup scripts.

它无法检测conda命令和python。如何修复此问题?

您使用什么操作系统创建startup.sh?我认为你有一个EOL问题(Unix和DOS)。Ubuntu 18.04是虚拟机的操作系统。你用什么操作系统创建startup.sh?编辑器使用的下线设置是什么?记事本++上的windows计算机。记事本创建具有windows DOS行结尾的文件。您需要使用VI或类似工具在Linux上重新创建该文件。DOS是
\r\n
。Linux/Unix/macOS是行结束(EOL)的
\n
。这是你的问题。