Making 'compiled' modules work with multiple python versions on Linux

2024-03-28 Thread Olivier B. via Python-list
I have a python module that includes some C++ code that links with the
Python C API

I have now modified the c++ code so that it only uses the Limited API,
and linked with python3.lib instead of python311.lib.

I can now use that python module with different python versions on Windows

But on Linux, it seems that linking to libpython3.so instead of
libpython3.11.so.1.0 does not have the same effect, and results in
many unresolved python symbols at link time

Is this functionality only available on Windows?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making 'compiled' modules work with multiple python versions on Linux

2024-03-29 Thread Olivier B. via Python-list
It is not a symlink on my system, where i built python myself, but a
15KB so file. But it seems to lack lots of python symbols.

Maybe what i should do is actually make libpython.so a physical copy
of libpyton311.so before linking to it, so now on any system the
module would look to load libpython.so, which could be pointing to any
version. I'll try that next

Le ven. 29 mars 2024 à 10:10, Barry  a écrit :
>
>
>
> > On 28 Mar 2024, at 16:13, Olivier B. via Python-list 
> >  wrote:
> >
> > But on Linux, it seems that linking to libpython3.so instead of
> > libpython3.11.so.1.0 does not have the same effect, and results in
> > many unresolved python symbols at link time
> >
> > Is this functionality only available on Windows?
>
> Python limited API works on linux, but you do not link against the .so on 
> linux I recall.
>
> You will have missed that libpython3.so is a symlink to libpython3.11.so.10.
>
> Windows build practices do not translate one-to-one to linux, or macOS.
>
> Barry
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


First two bytes of 'stdout' are lost

2024-04-11 Thread Olivier B. via Python-list
I am trying to use StringIO to capture stdout, in code that looks like this:

import sys
from io import StringIO
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
print( "patate")
mystdout.seek(0)
sys.stdout = old_stdout
print(mystdout.read())

Well, it is not exactly like this, since this works properly

This code is actually run from C++ using the C Python API.
This worked quite well, so the code was right at some point. But now,
two things changed:
 - Now using python 3.11.7 instead of 3.7.12
 - Now using only the python limited C API

And it seems that now, mystdout.read() always misses the first two
characters that have been written to stdout.

My first ideas was something related to the BOM improperly truncated
at some point, but i am manipulating UTF-8, so the bom would be 3
bytes, not 2.

I ruled out wrong C++ code to extract the string from the python
variable, since running a python print of the content of mystdout in
the real stdout also misses the two first characters.

Hopefully someone has a clue on what would have changed in Python for
this to stop working compared to python 3.7?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First two bytes of 'stdout' are lost

2024-04-11 Thread Olivier B. via Python-list
Partly answering myself:

For some reason, right after mystdout has been created, i now have to
do mystdout.seek(0) and this solves the issue.

No idea why though..

Le jeu. 11 avr. 2024 à 14:42, Olivier B.
 a écrit :
>
> I am trying to use StringIO to capture stdout, in code that looks like this:
>
> import sys
> from io import StringIO
> old_stdout = sys.stdout
> sys.stdout = mystdout = StringIO()
> print( "patate")
> mystdout.seek(0)
> sys.stdout = old_stdout
> print(mystdout.read())
>
> Well, it is not exactly like this, since this works properly
>
> This code is actually run from C++ using the C Python API.
> This worked quite well, so the code was right at some point. But now,
> two things changed:
>  - Now using python 3.11.7 instead of 3.7.12
>  - Now using only the python limited C API
>
> And it seems that now, mystdout.read() always misses the first two
> characters that have been written to stdout.
>
> My first ideas was something related to the BOM improperly truncated
> at some point, but i am manipulating UTF-8, so the bom would be 3
> bytes, not 2.
>
> I ruled out wrong C++ code to extract the string from the python
> variable, since running a python print of the content of mystdout in
> the real stdout also misses the two first characters.
>
> Hopefully someone has a clue on what would have changed in Python for
> this to stop working compared to python 3.7?
-- 
https://mail.python.org/mailman/listinfo/python-list


Changing path to python in pip.exe, ipython.exe, etc

2024-04-25 Thread Olivier B. via Python-list
I am building a python work environment where
 - i build python from sources
 - install pip with the wheel bundled with python
 - then install things with pip, like Jupyter

That environment is then deployed on various machines, at various
installation folders.

One issue I encounter, is the path to python in scripts like pip,
ipython, jupyter, etc is the original path where python is installed.
On linux, i can just do some sed in the problematic scripts.
On windows however, those scripts are python embedded in an EXE.
Probably generated by the same tool, as they all have a similar size
and a structure of an exe that contains a compressed __main__.py that
launch the relevant python module for the command.

What is the tool that creates those executables, and is there a way to
regenerate them from the python that has been deployed somewhere else,
so they point to the correct final path to python on that machine?
 Since pip is able to create ipython.exe with path to my python
embedded for example, i assume i already have all i need in my python
installation to regenerate them?
-- 
https://mail.python.org/mailman/listinfo/python-list