python cannot find module when using ssh

2024/9/16 22:47:47

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
Answer

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')

https://en.xdnf.cn/q/72232.html

Related Q&A

Python sklearn installation windows

When trying to install Pythons sklearn package on Windows 10 using pip I am given an EnvironmentError that tells me there is no such file or directory of a specific file: ERROR: Could not install packa…

Python PSD layers?

I need to write a Python program for loading a PSD photoshop image, which has multiple layers and spit out png files (one for each layer). Can you do that in Python? Ive tried PIL, but there doesnt se…

Multiple inheritance: overridden methods containing super()-calls

With the file super5.py:class A:def m(self):print("m of A called")class B(A):def m(self):print("m of B called")super().m()class C(A):def m(self):print("m of C called")supe…

Specifying the output file name in Apache Spark

I have a MapReduce job that Im trying to migrate to PySpark. Is there any way of defining the name of the output file, rather than getting part-xxxxx?In MR, I was using the org.apache.hadoop.mapred.li…

How to plot two DataFrame on same graph for comparison

I have two DataFrames (trail1 and trail2) with the following columns: Genre, City, and Number Sold. Now I want to create a bar graph of both data sets for a side by side comparison of Genre vs. total N…

Babel doesnt recognize jinja2 extraction method for language support

Im adding language translation support to my project. The code is on Python and has jinja2 in the html files, and Javascript.Im trying to use Babel to do the translation, but it doesnt recognize the ex…

Automatically simplifying/refactoring Python code (e.g. for loops - list comprehension)? [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.We don’t allow questi…

Knowing the number of iterations needed for convergence in SVR scikit-learn

I am trying to optimize an SVR model and facing a problem because of overfitting, to overcome this I have tried to decrease the number of iterations instead of leaving it until convergence.To compare …

Why is `NaN` considered smaller than `-np.inf` in numpy?

What is the reason that NaNs are considered less than -np.inf in any comparisons involving np.min or np.argmin?import numpy as np In [73]: m = np.array([np.nan, 1., 0., -np.inf]) In [74]: n = np.array…

recursion within a class

I am trying to place a recursive formula inside a class statementclass SomeNode:def __init__(self, a):leng = len(a)half= leng/2self.firstnode=a[0][0]self.child1=SomeNode([a[i]for k in range(leng)])self…