GCLOUD SSH和GCLOUD SSH-命令不一致的环境

发布于 2025-01-24 17:48:43 字数 741 浏览 0 评论 0 原文

我是GCP和CLI的新手。我正在尝试编写一个从深度学习图像中创建VM实例的脚本,然后在其上运行Python脚本。我在此处关注文档,以创建深度学习实例,CLI在这里工作正常。

当sshing进入创建的实例并用pip3冻结包装时,我会从深度学习图像中获得所有我期望的包装列表:

gcloud Compute compute compute ssh dl-instance

用户@dl-instance:pip3冻结

但是,尝试与 - 命令选项一行进行所有操作,提供了较小的软件包列表,例如四个或其他内容:

gcloud Compute compute concute ssh dl-instance - 命令“ pip3冻结”

,我真的无法访问诸如numpy或典型的python软件包之类的东西。我已经验证了这两种方法是通过运行Whoami在VM上使用同一用户。我注意到两种方法之间的$路径不同。有人知道为什么两种方法之间的环境不一致,以及如何同步它们?感谢任何输入,谢谢。

I am new to gcp and the cli. I'm trying to write a script which creates a vm instance from deep learning image then runs a python script on it. Im following the doc here to create the deeplearning instance https://cloud.google.com/compute/docs/instances/create-start-instance#publicimage, and the cli works fine here.

When ssh'ing into the created instance and checking the packages with pip3 freeze I get all the long list of packages I'd expect from deeplearning image:

gcloud compute ssh dl-instance
user@dl-instance: pip3 freeze

However, trying to do this all in one line with the --command option gives a much smaller list of packages, like four or something:

gcloud compute ssh dl-instance --command "pip3 freeze"

and i really don't have access to anything like numpy or typical python packages for deep learning. I've verified that the two methods are using the same user on the vm by running whoami. I have noticed that the $PATH's are different between the two methods. does anybody know why the environments are inconsistent between the two methods, and how to synchronize them? Any input is appreciated, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月朦胧 2025-01-31 17:48:43

约翰·汉利(John Hanley)的评论是正确的。登录时会运行许多脚本。在此链接上使用答案 https://unix.stackexchange.com/questions/334382/find-und-what-what-what-scripts-are-being-run-by-by-by-bash-at-login 我能够使用Strace列出由Shell运行的所有有效文件。查看这些内容,我发现文件加载conda环境是/etc/profile.d/env.sh。

明确地,为了利用图像python环境,我将在所有命令之前都使用“ ./etc/profile.d/env.sh&&”当使用-command flag到gcloud ssh

John Hanley's comment is correct. THere are a number of scripts which are run when logging in. Using the answer at this link https://unix.stackexchange.com/questions/334382/find-out-what-scripts-are-being-run-by-bash-at-login I was able to use strace to list all the valid files which are run by the shell. Looking at the contents of these I found that the file loading conda environment is /etc/profile.d/env.sh.

Explicitly, to make use of the image python environment I will have precede all commands with ". ./etc/profile.d/env.sh &&" when using the --command flag to gcloud ssh e.g.

gcloud compute ssh dl-instance --command=". /etc/profile.d/env.sh && python3 myscript.py"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文