0

I have to run a shell script on a Centos Linux machine that calls a python file. Inside the python file, there is the following code snippet:

from lib.rclone import Rclone
rclone = Rclone()
if shutil.which("rclone") == None:
     print("Rclone executable is missing, install it")`    

The problem is that I am not supposed to install any code (including rclone) on the machine. Therefore, whenever I call the shell script, it ends up with the error message. I don't know how can I successfully run it?

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
Quala
  • 1
  • 2
    "Install" can mean different things. Is copying something into your home directory or into a temporary directory "installing" it? This is more a system administration and policy/semantics question than it is a Python question; as such, I'm not sure it's on-topic here. – Charles Duffy Jan 24 '23 at 20:27
  • In Python `import` is actually an executable statement. – PM 77-1 Jan 24 '23 at 20:28
  • You say "the error message" as if you had shown it, but I don't see it... – Kelly Bundy Jan 24 '23 at 20:43
  • Is the library already installed and just doesn't get found? – Kelly Bundy Jan 24 '23 at 20:46

2 Answers2

2

The program you are running requires rclone. Since you cannot install it, you cannot run it. Simple as that.

Nathan Getty
  • 142
  • 4
  • @chepner, ...eh, it's _one_ answer; whether it's "the" answer depends on exactly what the people who wrote and are responsible for enforcing the OP's policy guidelines consider "installing". Is something installed if you transfer a zip file, open a read/write FD to it, delete it on-disk, and wire up your Python interpreter to be able to import from that deleted file? But that's an opinion-based question that's completely outside our scope; it's the OP's role to provide adequate definitions, so I'd argue that this question isn't answerable at all in current state. – Charles Duffy Jan 24 '23 at 20:32
  • I'm having trouble reading the question in any other way then "I can't put `rclone` on this machine". – chepner Jan 24 '23 at 20:33
  • @chepner, if you interpret the OP as asking about software installation / system administration, would you agree that the question is eligible for close-as-off-topic as not being about software development as such? – Charles Duffy Jan 24 '23 at 20:37
  • @chepner What if it's already installed? And they just need to "make it accessible" (e.g., adding its path so it can be found)? – Kelly Bundy Jan 24 '23 at 20:41
  • No, I think it's a valid question to ask about Python. Actually, one can probably write a custom `ResourceLoader` that could define a module in memory from a remote source. But I'm leaning towards a simple "no" as the answer to the question. – chepner Jan 24 '23 at 20:41
1

You can try to release the script as a .exe file. By using pyinstaller (https://pyinstaller.org/) you don't have to install any libs or py package on the target machine, you can even choose to release it as a single executable.

  • You're still copying that executable to the remote system, and depending on how pyinstaller is configured it's potentially unpacking executable files into `/tmp`; whether this is "installing" or not is a policy question, not a technical question. – Charles Duffy Jan 24 '23 at 20:35
  • @CharlesDuffy I got your point, and I agree with that, but as I interpreted the question, he has to execute a script, wrote in python, on a production machine, that doesn't have any python interpreter installed. That's my 2cents, no-more, no-less. – Alessandro Cerro Jan 24 '23 at 20:44