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
Yes. It also means that your user's .bashrc has something specific in it which modifies $PATH
to allow you to access extra modules. I don't like modifying path on a global level, personally, so I'll suggest the Python approach: call sys.path.append('/path/to/numpy')
I found the problem. It is truly the problem of python path.
And the reason why I didn't find this is that, instead of doing
ssh <server name> echo $PYTHONPATH
to find all the pathes python searches modules
we should do
ssh <server name> 'echo $PYTHONPATH'
we cannot ignore the quote to check variable PYTHONPATH on server
When running cmd over ssh in one line, the .profile is not read. To test, try this:
ssh host env
Use this instead to fix this issue (quotes are compulsory):
ssh host '. ~/.profile; cmd'
eg:
ssh <server name> '. ~/.bashrc; <python command>'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With