使用ssh时python找不到模块 [英] python cannot find module when using ssh

查看:71
本文介绍了使用ssh时python找不到模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上使用 python.当我运行需要 numpy 模块的 python 命令时,如果我这样做

ssh <服务器名称><python命令>

<块引用>

那个服务器会抱怨没有找到名为 numpy 的模块.

但是,如果我首先通过 ssh 连接到该服务器

ssh <服务器名称>

然后在该服务器上运行该 python 命令

一切都会好的.

这意味着服务器已经安装了numpy模块,只是我不登录就找不到模块.

猜猜可能是什么问题?

谢谢

<块引用>

添加:

抱歉忘记说了,我运行得到的结果

ssh <服务器名称>哪条蟒蛇ssh <服务器名称>回声 $PYTHONPATHssh <服务器名称>回声 $PYTHONUSERBASEssh <服务器名称>回声 $LD_LIBRARY_PATH

<块引用>

和我第一次 ssh 到服务器时一样

ssh <服务器名称>

<块引用>

然后运行这些命令

哪个蟒蛇回声 $PYTHONPATH回声 $PYTHONUSERBASE回声 $LD_LIBRARY_PATH

解决方案

遇到了同样的问题并尝试了上述所有方法.

对我有用的是将远程命令从 python 更改为完整路径.

1) SSH 到您的遥控器,通过

找出您的 python 所在的位置

2) 将您的命令从 python pyscript.py 更改为 remote/path/to/python pyscript

I'm using python on servers. When I run a python command which needs numpy module, if I do

ssh <server name> <python command>

that server will complain no module named numpy found.

However, if I first ssh to that server by

ssh <server name>

then run that python command on that server

<python command>

everything will be ok.

This means that server has already been installed numpy module, and it just cannot find the module without my logging on it.

Any guess of what the problem could be?

Thanks

Add:

sorry for forgetting to mention that, the result I got by running

ssh <server name> which python
ssh <server name> echo $PYTHONPATH
ssh <server name> echo $PYTHONUSERBASE
ssh <server name> echo $LD_LIBRARY_PATH

are all the same as when I first ssh to the server

ssh <server name>

then run those commands

which python
echo $PYTHONPATH 
echo $PYTHONUSERBASE
echo $LD_LIBRARY_PATH

解决方案

Had the same issue and tried everything above.

What worked for me was changing the remote commands from python to the full path.

i.e.

1) SSH onto your remote, find out where your python is located via

2) change your command from python pyscript.py to remote/path/to/python pyscript

这篇关于使用ssh时python找不到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆