Skip to main content

Hi all

Is there a way tu call pip via RUNPY?

Usually I do server maintenance and intallations via shell, like this

SH-5.1$ /u2/uv/python/bin/python3 -m pip install some_module

SH-5.1$ /u2/uv/python/bin/python3 -m pip freeze

Of course, it the server is running on windows things are different, so I was wondering if there is some way to interface with pip using the Universe command line, and not the operative system shell.



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Hi all

Is there a way tu call pip via RUNPY?

Usually I do server maintenance and intallations via shell, like this

SH-5.1$ /u2/uv/python/bin/python3 -m pip install some_module

SH-5.1$ /u2/uv/python/bin/python3 -m pip freeze

Of course, it the server is running on windows things are different, so I was wondering if there is some way to interface with pip using the Universe command line, and not the operative system shell.



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Hector,

I do not believe it would work with RUNPY.

Have you looked at doing it pragmatically?

https://www.pynerds.com/call-pip-programmatically/ 



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Hector,

I do not believe it would work with RUNPY.

Have you looked at doing it pragmatically?

https://www.pynerds.com/call-pip-programmatically/ 



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Has anyone tried uv?  (Yes - just a coincidence that it's uv).  Not sure if it will help in this situation

https://docs.astral.sh/uv/guides/scripts/



------------------------------
Karl Pozmann
Akron, OH
------------------------------

Hector,

I do not believe it would work with RUNPY.

Have you looked at doing it pragmatically?

https://www.pynerds.com/call-pip-programmatically/ 



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Hi, Mike

The latest versions of the pip module hid the ways to call to the "freeze" equivalent from inside Python. It can be done, but it's a hack.

from pip._internal.operations import freeze

"If you're directly importing pip's internals and using them, that isn't a supported usecase".

Another alternative is:

import pkg_resources
env = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set)

But it has too much noise in it.

Anyways, my problem is that I need logic to detect if the server is running Linux or Windows:

with uopy.connect(**config) as s:
if servidor['operationSystem'] == 'NT':
comando_pip = 'DOS /c "C:\\\\uv\\\\uv\\\\python\\\\python.exe -m pip freeze'
else:
comando_pip = 'SH -c "/u2/uv/python/bin/python3 -m pip freeze'
cmd = uopy.Command(comando_pip)
cmd.run()
self.__modulos_pip = cmd.response.split()



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------