Re: How to force the path of a lib ?
dieter wrote: > Vincent Vande Vyvre writes: >> I am working on a python3 binding of a C++ lib. This lib is installed >> in my system but the latest version of this lib introduce several >> incompatibilities. So I need to update my python binding. >> >> I'm working into a virtual environment (py370_venv) python-3.7.0 is >> installed into ./localpythons/lib/python3.7 >> >> So, the paths are: >> # python-3.7.0 >> ~/./localpythons/lib/python3.7/ >> # my binding python -> libexiv2 >> ~/./localpythons/lib/python3.7/site-packages/pyexiv2/*.py >> ~/./localpythons/lib/python3.7/site- packages/pyexiv2/libexiv2python.cpython-37m-x86_64-linux-gnu.so >> >> # and the latest version of libexiv2 >> ~/CPython/py370_venv/lib/libexiv2.so.0.27.0 >> >> All theses path are in the sys.path >> >> Now I test my binding: > import pyexiv2 >> Traceback (most recent call last): >> File "", line 1, in >> File >> "/home/vincent/CPython/py370_venv/lib/python3.7/site- packages/py3exiv2-0.1.0-py3.7-linux-x86_64.egg/pyexiv2/__init__.py", >> line 60, in >> import libexiv2python >> ImportError: >> /home/vincent/CPython/py370_venv/lib/python3.7/site- packages/py3exiv2-0.1.0-py3.7-linux-x86_64.egg/libexiv2python.cpython-37m- x86_64-linux-gnu.so: >> undefined symbol: _ZN5Exiv27DataBufC1ERKNS_10DataBufRefE > >> >> Checking the libexiv2.so the symbol exists >> ~/CPython/py370_venv/lib$ objdump -T libexiv2.so.0.27.0 >> >> 0012c8d0 gDF .text000f Base >> _ZN5Exiv27DataBufC1ERKNS_10DataBufRefE >> >> >> But it is not present into my old libexiv2 system, so I presume python >> use /usr/lib/x86_64-linux-gnu/libexiv2.so.14.0.0 (The old 0.25) instead >> of ~/CPython/py370_venv/lib/libexiv2.so.0.27.0 (The latest 0.27) >> >> How can I solve that ? > > To load external C/C++ shared objects, the dynamic lickage loader > (ldd) is used. "ldd" does not look at Pthon's "sys.path". > Unless configured differently, it looks at standard places > (such as "/usr/lib/x86_64-linux-gnu"). > > You have several options to tell "ldd" where to look for > shared objects: > > * use the envvar "LD_LIBRARY_PATH" >This is a "path variable" similar to the shell's "PATH", >telling the dynamic loader in which directories (before >the standard ones) to look for shared objects > > * use special linker options (when you link your Python >extension shared object) to tell where dependent shared >object can be found. > To follow up on that last point, look up --rpath and related. -- https://mail.python.org/mailman/listinfo/python-list
generate matplotlib images without having access to an X server
The following piece of code is supposed to generate images for plotting:
(in *bold*, my added / corrected statements)
...
*# JP handle non X server*
*import matplotlib*
*matplotlib.use('Agg')*
# JP
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
...
# Generate images from noise, using the generator network.
f, a = plt.subplots(4, 10, figsize=(10, 4))
for i in range(10):
# Noise input.
z = np.random.uniform(-1., 1., size=[4, noise_dim])
g = sess.run([gen_sample], feed_dict={gen_input: z})
g = np.reshape(g, newshape=(4, 28, 28, 1))
# Reverse colours for better display
g = -1 * (g - 1)
for j in range(4):
# Generate image from noise. Extend to 3 channels for matplot
figure.
img = np.reshape(np.repeat(g[j][:, :, np.newaxis], 3, axis=2),
newshape=(28, 28, 3))
a[j][i].imshow(img)
*# JP HAck*
*# see
https://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server
*
*# "tuple packing" ->
https://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences
*
*#f.show()*
*#plt.draw()*
*#plt.waitforbuttonpress()*
*#a.savefig('a.png')*
*f.savefig('f.png')*
To make it run, I commented out all plt.* statements. Indeed it runs and it
produces the 'f.png' picture.
However, when the statement:
a.savefig('a.png')
is also activated (i.e. not commented out), the program ends with the
following exception:
* a.savefig('a.png')*
*AttributeError: 'numpy.ndarray' object has no attribute 'savefig'*
Anything I am missing? I am not familiar with the code, just trying to
understand it.
Thank you
--
Regards,
Joseph Pareti - Artificial Intelligence consultant
cell +49 1520 1600 209
cell +39 339 797 0644
--
https://mail.python.org/mailman/listinfo/python-list
Re: What is your experience porting Python 2.7.x scripts to Python 3.x?
On 2019-01-22, Cameron Simpson wrote: > On 22Jan2019 19:20, Grant Edwards wrote: >>On 2019-01-22, Schachner, Joseph wrote: >>> For anyone who has moved a substantial bunch of Python 2 to Python >>> 3, can you please reply with your experience? >> >>If you used bytes (or raw binary strings) at all (e.g. for doing >>things like network or serial protocols) you're in for a lot of pain. > > Yes, but you will be the better for it afterwards. It's a lot better if you're leaving Python2 behind. If you're maintaing 2/3 compatible code that uses bytes, the pain is chronic rather than acute. > I've had a few programs which worked with binary data, and often > also "text". In Python 2 there was _constant_ uncertanty when these > were mixed (writing text into binary fields and related). In Python > 3 I am never confused. It is a huge win. For whatever reason, I guess I never ran into that very much. -- Grant Edwards grant.b.edwardsYow! Here I am in the at POSTERIOR OLFACTORY LOBULE gmail.combut I don't see CARL SAGAN anywhere!! -- https://mail.python.org/mailman/listinfo/python-list
SCons 3.0.4 Release
A new SCons release, 3.0.4, is now available on the SCons download page: http://www.scons.org/download.php Or via pypi: pip install scons Here is a summary of the changes since 3.0.3: NEW FUNCTIONALITY - Added TEMPFILESUFFIX to allow user to specify suffix for tempfiles used for long command lines - Initial support for ARM architectures with Microsoft Visual Studio 2017. You must set TARGET_ARCH to arm or arm64 to enable. FIXES - Fixed issue detecting installs of Microsoft Visual Studio 2017 as well as Microsoft build tools 2017. git shortlog --no-merges -ns 3.0.3..HEAD 17 Daniel 10 Mats Wichmann 4 Daniel Moody 4 William Deegan 3 anatoly techtonik 1 Tobias Herzog -- https://mail.python.org/mailman/listinfo/python-list
Re: What is your experience porting Python 2.7.x scripts to Python 3.x?
On 23Jan2019 14:15, Grant Edwards wrote: On 2019-01-22, Cameron Simpson wrote: On 22Jan2019 19:20, Grant Edwards wrote: On 2019-01-22, Schachner, Joseph wrote: For anyone who has moved a substantial bunch of Python 2 to Python 3, can you please reply with your experience? If you used bytes (or raw binary strings) at all (e.g. for doing things like network or serial protocols) you're in for a lot of pain. Yes, but you will be the better for it afterwards. It's a lot better if you're leaving Python2 behind. If you're maintaing 2/3 compatible code that uses bytes, the pain is chronic rather than acute. Um, yes, very true. I've had a few programs which worked with binary data, and often also "text". In Python 2 there was _constant_ uncertanty when these were mixed (writing text into binary fields and related). In Python 3 I am never confused. It is a huge win. For whatever reason, I guess I never ran into that very much. The instance I have in mind was a fairly complex bit of code doing lots of binary and also strings in Python 2. It is now Python 3 only and far cleaner. As as you suggest, _not_ Python 2 compatible. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: What is your experience porting Python 2.7.x scripts to Python 3.x?
Cameron Simpson schrieb am 23.01.19 um 00:21: > from __future__ import absolute_imports, print_function > > gets you a long way. ... and: division. Stefan -- https://mail.python.org/mailman/listinfo/python-list
Re: What is your experience porting Python 2.7.x scripts to Python 3.x?
On Wed, Jan 23, 2019 at 1:36 PM Stefan Behnel wrote: > > Cameron Simpson schrieb am 23.01.19 um 00:21: > > from __future__ import absolute_imports, print_function > > > > gets you a long way. > > ... and: division. All right, but apart from absolute imports, the print function, and true division, what has Python 3.x ever done for us? *ducks* -- https://mail.python.org/mailman/listinfo/python-list
Re: ValueError: Input contains NaN, infinity or a value too large for dtype('float32')
> You may be using the sklearn package incorrectly; you'll > have to read the (apparently quite prolific) documentation yourself, > I've never used it. > > -- > Rhodri James *-* Kynesim Ltd So why would you try to answer it? I have the same issue but there are no NaN, infinites, negative infinites or large values. -- https://mail.python.org/mailman/listinfo/python-list
Re: checking protocols.
Avi Haven't noticed an answer to this. Did I miss anything? On 20/01/19 11:07 AM, Avi Gross wrote: Short question. Checking if a protocol is set up? =do you mean that to check/require that a class exhibits a particular protocol we should use abstract classes - will not instantiate unless all the required components are coded? Many python improvements are changes to classes that implement a protocol. There are things you can do to make your own classes work with the protocol by setting various dunder variables like __iter__, __next__ and writing appropriate ode including throwing the right error class when done. Similarly the "with" statement works with objects that implement __enter__ and __exit__. There can be plenty of others like this and more can be anticipated in the future. So, several related questions. Tools that help a developer add appropriate things to an object to implement the protocol or to test if it was done right. Perhaps a function with a name like is_iterable() that tells if the protocol can be applied. For the specific case of an iterable, I found something that seems to work for at least some cases: from collections import Iterable item = [1, 2, 3, 4] isinstance(item, Iterable) Not sure if it would work on one I created that did the right things or what it checks. =your code should be 'approved' if it implements the next() method, etc. Did you try such? I am interested in a pointer to something that describes many of the known protocols or extensions and maybe to modules designed sort of as I said above. I am aware some protocols may be not-quite standard with parts of the protocol embedded in different objects like wrappers or objects returned upon a request to have a proxy and many other techniques that seem to abound and allow multiple layers of indirection or seemingly almost magical as in multiple inheritance drop-ins and so on. That is what may make these things harder if someone uses something like __getattr__ or descriptors to intercept calls and provide the functionality without any actual sign of the dunder key normally expected. =Questioning similarly, I recall finding one of these - but do you think that I can re-find it now? Apologies. I (too) think it would be handy to have such a list. There are many for the 'magic methods' themselves, in all the better Py3 texts. Yesterday I needed to add __LT__() to allow a list of class instances to be sorted, __EQ__ to enable a list of (other) instances to be searched (if element in list_of_instances), and made a class callable (__call__()). Each time I wondered: is this the best way to accomplish or is there already a mechanism I could be employing/not 'reinventing the wheel'. (perhaps incompletely!) For your further reading pleasure (maybe): On the this topic, one of many references is Interfaces in Python: Protocols and ABCs http://masnun.rocks/2017/04/15/interfaces-in-python-protocols-and-abcs/ Which reminded me of the amusingly titled: Duck Typing vs. Goose Typing, Pythonic Interfaces https://dgkim5360.github.io/blog/python/2017/07/duck-typing-vs-goose-typing-pythonic-interfaces/ Diving into the docs (although not finding exactly what we seek): https://docs.python.org/3/library/abc.html - didn't include all, eg context managers: https://docs.python.org/3/library/contextlib.html At a deeper level: https://docs.python.org/3/c-api/abstract.html?highlight=abstract and https://docs.python.org/3.6/c-api/object.html - again, incomplete in the sense (I gained) of this enquiry. Hopefully there's something to keep your mind occupied... -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: checking protocols.
On Thu, Jan 24, 2019 at 11:40 AM DL Neil wrote: > > Avi > > Haven't noticed an answer to this. Did I miss anything? > No idea where you originally sent it, but I didn't see it until just now. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
RE: checking protocols.
See reply BELOW in sections marked by ==: -Original Message- From: DL Neil Sent: Wednesday, January 23, 2019 7:39 PM To: Avi Gross ; [email protected] Subject: Re: checking protocols. Avi Haven't noticed an answer to this. Did I miss anything? ==REPLY ON non-TOP as requested on 1/23/2019 Dave, I never saw the original message appear and thus expected no replies. I see a later post by Chris indicating he did not see it either. I assumed perhaps a moderator needed to approve it. My question really boils down to being intrigued how the python language can be extended using documented protocols in more ways and having a place where you can see a list of the ones out there and a way to join in with your own classes reliably and so on. I note there may be many unpublished protocols used internally within modules that also create similar structures but do not expect to be emulated. I see interpolated comments below and will interpolate within that but it gets confusing. ==END first set of remarks on 1/23/2019 ==ORIGINAL MESSAGE BELOW if anyone wants to see in-line comments and supply info.=== On 20/01/19 11:07 AM, Avi Gross wrote: > Short question. Checking if a protocol is set up? =do you mean that to check/require that a class exhibits a particular protocol we should use abstract classes - will not instantiate unless all the required components are coded? == I am not looking for any specific options but indeed including an abstract class might be one way to go. It might supply a reasonable way to ask if the class you make yourself INTENDS on running that protocol and would enforce the presence of the required methods somewhere in the inheritance chain. Of course the functions could be stubs that don't do the right thing, or anything passable. > Many python improvements are changes to classes that implement a protocol. > There are things you can do to make your own classes work with the > protocol by setting various dunder variables like __iter__, __next__ > and writing appropriate ode including throwing the right error class when > done. > Similarly the "with" statement works with objects that implement > __enter__ and __exit__. There can be plenty of others like this and > more can be anticipated in the future. > > So, several related questions. Tools that help a developer add > appropriate things to an object to implement the protocol or to test > if it was done right. Perhaps a function with a name like > is_iterable() that tells if the protocol can be applied. For the > specific case of an iterable, I found something that seems to work for at > least some cases: > > from collections import Iterable > item = [1, 2, 3, 4] > > isinstance(item, Iterable) > > Not sure if it would work on one I created that did the right things > or what it checks. =your code should be 'approved' if it implements the next() method, etc. Did you try such? ==Just to be clear, yes. That is the current state of affairs. ANY CODE can be run but probably fails when it does not follow the recipe. Any of many places that expect the iteration protocol will ask for a __iter__ and either catch the error or fail. If it works, they will call __next__ as often as needed and may or may not fail well if it is not found. And, as noted, the function may throw the right error object on completion or not and that may cause the caller to fail mysteriously or be bypassed if some other error is thrown instead. What I am hoping for is OPEN to multiple solutions or to be told there is no such need. One solution would be something that can be used to exercise the function and report if the protocol is being honored. In this case, that is fairly trivial. Just try the object in one of many places the iterator protocol is used. It may be less clear how you check if the 'with' protocol is satisfied as it may not properly close whatever it is guarding like closing a file or freeing a lock. If you test that you may not notice the file remains open and so on. But will your code also work if the user closed the file already on purpose? > I am interested in a pointer to something that describes many of the > known protocols or extensions and maybe to modules designed sort of as > I said above. I am aware some protocols may be not-quite standard with > parts of the protocol embedded in different objects like wrappers or > objects returned upon a request to have a proxy and many other > techniques that seem to abound and allow multiple layers of > indirection or seemingly almost magical as in multiple inheritance > drop-ins and so on. That is what may make these things harder if > someone uses something like __getattr__ or descriptors to intercept > calls and provide the functionality without any actual sign of the dunder key > normally expected. =Questioning similarly, I recall finding one of t
