1

I have a local script that I want to run on a remote server using my local python installation. I need to do this because I have specific packages installed which I am unable to install on the remote server.

I tried two solutions I found but neither are working.

ssh user@remote python -u < script.py 

and

cat script.py | ssh user@remote python -

Both of the above give me the ImportError for a module installed only on my local machine. I definitely have access to run code on the server using their installation but cannot install anything myself.

I tried to clone the server's python but get this error:

user@server:~$ conda create -n my_root --clone="/opt/anaconda"
Source:      /opt/anaconda
Destination: /home/user/.conda/envs/my_root
The following packages cannot be cloned out of the root environment:
- conda-4.3.17-py27_0 
- conda-env-2.6.0-0 
Fetching package metadata .........
Packages: 153
Files: 0
ERROR conda.core.link:_execute_actions(335): An error occurred while             
installing package 'defaults::pycairo-1.10.0-py27_0'.
IOError(13, 'Permission denied')
Attempting to roll back.
IOError(13, 'Permission denied')
3
  • 1
    If the modules aren't on the remote server, they can't be used by code run on the remote server. That they are on the machine you use to connect to the remote server from is irrelevant. Commented Apr 15, 2019 at 12:54
  • Depending on what exactly you are trying to achieve, you can execute the code locally and get the output onto the server. Otherwise, it's impossible to run something that doesn't have all dependencies satisfied. Commented Apr 15, 2019 at 13:06
  • 1
    To cut the long story short: that's not how it works. Commented Apr 15, 2019 at 13:06

3 Answers 3

1

If python is installed on the remote machine all you need to do is pip install any modules that you are using in script.py. You can check if it's installed with python -V.

Sign up to request clarification or add additional context in comments.

4 Comments

The user might be restricted of doing this though.
@VnC They're getting ImportError so they have permission to run the script
Again, depending on the server configuration, they might have access to a certain directory, where they can execute things, but not have access to install. If that works .. fine, but it sounds like a security vulnerability
@VnC I guess somebody might try to configure a server to allow python scripts from an ssh user but not let them pip install, but that seems off topic since the question is specifically about ImportError
0

It's not possible to run scripts on a remote server unless it's set up to allow you to do so. As you can imagine, it would be a pretty severe security vulnerability if you could!

What is it that you're trying to achieve?

Comments

0

If there is a restriction that you can not install the module on the server's global pip directory, you can use the Python virtual environment to virtually isolate your script from the server operating system install modules.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.