简体   繁体   中英

Modules appear to not be installed when running python through ssh

I am connecting to a remote server through

ssh user@server.com

and run

python script.py

in the appropriate directory. However, I get the error

ImportError: No module named numpy

even though I know the module is installed and the script runs with no problems when I am physically logged in to that server.

None of the answers I was able to find worked (for example this , and this ). Do have any ideas as to how I can run the script using ssh?

The remote server has Python 2.6.6 installed, and

which python

returns

/usr/bin/python

The remote serves runs CentOS.

See similar problem describe here: Why does an SSH remote command get fewer environment variables then when run manually? .

Compare your environment variables in the local (physical) mode to the remote mode by running env in both cases. Move missing variables from your local profile to /etc/profile. Then log out from ssh session and connect again.

Another approach: If you don't want to change anything, then after ssh switch to your user via su - <your user> . This may look weird because you already logged it with this user. The difference is, that after su all your env. variables will set like in a local (physical) mode. Advantage: it is quick. Disadvantage: You will have to do it each time you want to run your Python script. So the first approach with configuring /etc/profile may be better on the long run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM