Execute phython script(connect DB, execute SQL scripts) from remote server where no python installed

I have a created a python script to execute some SQLs for SQL servers.

description:
Server A: SQL server1( no download access, no internet , protected from firewall restricted )
Server B: SQL server2( no download access ,no internet ,protected from firewall restricted )
Server C: Jump box/ other windows server/ no download access protected from firewall restricted
Python script logic: access Server A and execute SQLs and write back to Server B
Laptop: Can have internet , enable downloads

Plan is to execute python from Server C.
Question: Since i am using pyodbc I m not able to down load from Server C. however I can access from my Laptop. Still i can download python software from python.org from my laptop and copy those offline files to Server C. “PIP:” commands are not working from Server C

Plan is python scripts to execute from SERVER C. please advice how i can achieve this

many thanks

Hello, @Udara. Welcome to Python!

It sounds like you have written some Python code which connects to SQL servers, and sends them some SQL queries for them to run. But I hear you saying that those servers are restricted, so that you cannot run Python scripts there.

If I am understanding you correctly, you do not need to run Python scripts on the SQL servers. Their SQL database server is set up to receive queries over the network from a database driver library on client machines. Your Python script runs on a client machine. I imagine it calls a database driver library, which in turn connects to the SQL server. There is no need for you to run a script on that SQL server.

Do I understand your situation correctly?

Good luck with your scripting!
—Jim DeLaHunt, Vancouver, Canada

Hi Jim Thank you for the quick reply. my remote server is not a SQL server. that is other job scheduling remote client. I am planing to run that python script from remote server which connect to SQL server and execute scripts periodically. pythons and pyodbc drivers () unable to install those client servers(my scripts are using drivers to connect SQL Servers). I can download python some other and can install on client server . however pyodbc unable to install(C:\python -m pip install pyodbc) on client servers as no internet access restricted.
therefore i am thing to have any option to run poython script client server(with no python) or how to install pyodbc(not available to download separately ) after download to other local server

hope this is clear to you
thanks

I am sorry the second post did not make it much clearer. For example it is not clear from which perspective a machine is “remote” or what you mean by “client server”. If you need to explain the setup further I suggest you to list the individual machines with names (e.g. “server1_sql”, “server2”, “client_workstation”…) and explain their roles, which services must/should be running on every machine and what are the limitations on every machine.

…but I have some suggestions which may help you:

  1. If the connection to PyPI has to go through an HTTP proxy, pip supports that:

https://pip.pypa.io/en/stable/user_guide/?highlight=proxy#using-a-proxy-server

  1. You can install Python packages from PyPI offline:
  1. If you just need to invoke execution of commands on a different machine, provide data to it through a command line and standard input and read standard output then you can use SSH for that. You can also use SSH to transfer files if the standard input and output is not enough. Note: Probably on Windows there are also different solutions for that but SSH is a part of Windows for some years already.

It is not entirely clear to me, sorry.

Still, it sounds to me like you want to install software on your “remote server” as part of building your system, but system administration policies on the “remote server” do not allow that. This sounds to me like a system administration question, not really a Python question.

Hi Jim I am explaining the requirement briefly as follows
Server A: SQL server1( no download access, no internet , protected from firewall restricted )
Server B: SQL server2( no download access ,no internet ,protected from firewall restricted )
Server C: Jump box/ other windows server/ no download access protected from firewall restricted
Python script logic: access Server A and execute SQLs and write back to Server B
Laptop: Can have internet , enable downloads

Plan is to execute python from Server C.
Question: Since i am using pyodbc I m not able to down load from Server C. but I can access from my Laptop. Still i can download python software from python.org from my laptop and copy those offline files to Server C. “PIP:” commands are not working from Server C

Plan is python scripts to execute from SERVER C

I think Jim and vaclav have some clear picture on the plan
thanks

Hi Vacla, I have updated the requirement . please review
thank you

Hi, Udara:

Thank you for making your requirements clearer. I like your terms “Server A”, “Server B”, “Server C”. It makes your question easier to understand.

Good!

  1. Can you download the Python installer for Windows to your laptop?
  2. Can you copy that Python installer file to Server C?
  3. Can you run that Python installer file on Server C?
  4. Can you connect to Server C, open a Command prompt window, and run python.exe --version? What happens?
  5. Can you connect to Server C, open a Command prompt window, and run pip.exe --version? What happens?

It is expected that Pip commands do not work until you install Pip. The Python installer for Windows also installs Pip. Once you install Python on Windows, Pip should also run. Server C’s restrictions may prevent Pip from connecting to the Internet, but Pip should run.

I will mention that I found it difficult to find a specific statement on the Python website that the Python installer for Windows actually does also install Pip. Does anyone have a link to an official Python page which lists everything that the Python installer for Windows installs?

Hi Jim
I copied the python installation to Server C , sucessfully installed it. however due to pyodbc is not available i am getting following error while run import pyodbc
FoundError: No module named ‘pyodbc’

  • Can you download the Python installer for Windows to your laptop? yes
  • Can you copy that Python installer file to Server C? yes
  • Can you run that Python installer file on Server C? yes
  • Can you connect to Server C, open a Command prompt window, and run python.exe --version? What happens?

PS C:\Installation\Phython\codes> python --version
Python 3.10.4

  • Can you connect to Server C, open a Command prompt window, and run pip.exe --version? What happens?
    [/quote]
    PS C:\Installation\Phython\codes> pip --version
    pip 22.0.4 from C:\Python\Python310\lib\site-packages\pip (python 3.10)
    PS C:\Installation\Phython\codes>
    PS C:\Installation\Phython\codes>

Excellent! Well done. You now have Python and Pip installed and working on Server C.

The next step is to use your laptop to download pyodbc and any other Python modules you need: from pypi.org, via the internet, to your laptop. Then you copy the directory with the Python modules to Server C. Then you connect to Server C, and use Pip on server C to install pyodbc etc. from the directory of modules which you copied from your laptop.

Václav Brožíkvbrozik gave you a helpful link for these steps, a day ago:

Try that, and see how it goes for you.

1 Like

Hi Jim Thats is perfect solution from Vaclav and it works for me. many many thanks for Vaclav and you and more responsive to the issue I had and support given is excellent.

two more questions I have to clarify please

  1. since I download pyodbc module. How do I know what are the latest available version and versions before I download it any modules I needed it in future
    ex: pyodbc-4.0.34

  2. how do we update in to latest version of the modules/pip when we have it ( from Server C)

thanks

Hi, @Udara :

I’m glad the answers were helpful! I hope it goes smoothly for you.

Your questions about how to perform updates are good ones. Sorry, I am not a good person to answer them. You would think that the operation of requiring a module, and updating it to the latest version, would be simple because it is so important. But unfortunately, there are many ways to do it, and many of them are complex. Having Server C be unable to directly download the updates makes it more complex. I will leave that question for someone else.

Consider writing a new topic, asking a new question, with a new title. People who know about updating packages might look at the title of this topic, “Execute python script from remote…”, and decide it is not the question for them. Instead, ask a question about how to update a package via a relay machine.

1 Like

There is a relatively new (still marked experimental) subcommand of pip for that:

pip index versions pyodbc

I have not tested it but I think you should just add the usual --upgrade or -U option to the pip install subcommand:

pip install --no-index --find-links /path/to/download/dir/ --upgrade -r requirements.txt
# or for a single package:
pip install --no-index --find-links /path/to/download/dir/ --upgrade pyodbc
2 Likes