Re: building 3.7.1 from source, _ctypes and libffi troubles

2018-12-21 Thread Anssi Saari
"Fetchinson . via Python-list"  writes:

> And as far as I know pkg-config is used by python's configure script
> so everything should be fine. I also set
> LD_LIBRARY_PATH=/home/fetch/opt/lib:/home/fetch/opt/lib64 and also
> C_INCLUDE_PATH=/home/fetch/opt/include

I looked into this a little. I found that setting C_INCLUDE_PATH as you
did disables finding libffi headers since pkg-config prints nothing with
pkg-config --cflags libffi then and it seems the headers are found with
pkg-config.

As for the libraries, detect_modules() in setup.py wants to find extra
library directories from the generated makefile so you need to make sure
they actually go in there, like this for example:

LDFLAGS=`pkg-config --libs-only-L libffi` ./configure

Then you'll have CONFIGURE_LDFLAGS and PY_LDFLAGS set in the generated
makefile and setup.py will pick up the directory from there.

Anyways, hope it helps. This worked for me on Ubuntu 16.04.5 LTS.

-- 
https://mail.python.org/mailman/listinfo/python-list


release: a function to express the 4 steps of math calculation in markdown format

2018-12-21 Thread oyster
I wrote a post on
https://stackoverflow.com/questions/53833884/failed-to-show-calculation-steps-with-sympy-and-markdown

Now I wrote https://github.com/retsyo/expand_expression to answer the
post partly

I released it for it can help others.

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ah, progress...

2018-12-21 Thread ant
dieter wrote:
> ant  writes:
>> ...
>>   in order to get this far below i had to edit each
>> file and put a try: except: around each import
>> statment checking if the module could be found
>> like (as an example):
>>
>> try:
>> import config as cfg
>> except:
>> import frog.config as cfg
>
> Is "frog" the package, you want to install?
> Then always use "import frog.config ...".

  frog is my temporary adaptation of my project
to test out how to do this without actually making
all those changes until i'm sure it is doing what
i want.

  frog is a package as i understand it.  here is
the structure:

=
(env) me@ant(15)~/src/salsa/frog$ find . -print | grep -v ".git" | grep -v 
"__pycache__" | grep -v "dist" | grep -v "build" | sort
.
./frog
./frog/active.py
./frog/background.py
./frog/board.py
./frog/commands.py
./frog/config.py
./frog/dialog.py
./frog/doc
./frog/doc/ngfp.6
./frog.egg-info
./frog.egg-info/dependency_links.txt
./frog.egg-info/entry_points.txt
./frog.egg-info/PKG-INFO
./frog.egg-info/requires.txt
./frog.egg-info/SOURCES.txt
./frog.egg-info/top_level.txt
./frog/history.py
./frog/__init__.py
./frog/labels.py
./frog/__main__.py
./frog/marbles.py
./frog/my_init.py
./frog/ngfp.py
./frog/png
./frog/png/arrows
./frog/png/arrows/picDDownW.png
./frog/png/arrows/picDLeftW.png
...80 lines skipped...
./frog/png/misc/sink_inv.png
./frog/png/misc/sink_orig.png
./frog/randboard.py
./LICENSE
./LICENSE.GPL
./MANIFEST.in
./NOTICE
./README.md
./setup.cfg
./setup.py
=


> Python locates (top level) packages/modules via the so
> called "Python path" (--> "sys.path"). When
> you run a script, the "Python path" is extended by the
> directory the script resides in -- thus a script typically
> can import "local" packages/module (residing in its directory).
> However, it is good practise to always access installed
> packages via their "official package path" (which
> in your case likely means "frog.config").

  this is the first i'm hearing of a path being
extended.  why isn't that reflected when i print the
current working directory when the program is running
(in both cases the paths show identical)?

  this is also the first time i'm hearing of "official
package path".

  there are likely the details i'm beating my head
against...  thank you.  :)


> When you develop a package, it may not yet be installed.
> This might hinder you to import in the "official" way.

  correct.  when i am testing/writing code i am in the
source code directory above called frog which
looks like:

=
-rw---  1 me me  8962 Dec 21 00:20 active.py
-rw---  1 me me  6673 Dec 21 00:11 background.py
-rw---  1 me me 11796 Dec 21 00:10 board.py
-rw---  1 me me   217 Dec 20 23:16 commands.py
-rw---  1 me me  5987 Dec 21 00:12 config.py
-rw---  1 me me 34077 Dec 21 00:14 dialog.py
drwx--  2 me me  4096 Dec 18 09:26 doc
-rw---  1 me me  1943 Dec 21 00:15 history.py
-rw---  1 me me   310 Dec 20 23:39 __init__.py
-rw---  1 me me  1845 Dec 21 00:15 labels.py
-rw---  1 me me   140 Dec 20 22:39 __main__.py
-rw---  1 me me 23973 Dec 21 00:17 marbles.py
-rw---  1 me me 13534 Dec 21 00:34 my_init.py
-rw---  1 me me 10354 Dec 21 09:02 ngfp.py
drwx-- 10 me me  4096 Dec 18 09:26 png
-rw---  1 me me  5514 Dec 21 00:18 randboard.py
(env) me@ant(18)~/src/salsa/frog/frog$ 
=

  so to test the code i simply run it via

$ python3 ngfp.py

  which works as i expect it.

=


> I work around this by using "setuptools" and its "setup"
> function in my "setup.py". "setuptools" supports the
> command "develop" (activated via "python setup.py develop")
> which "installs" the package in a way that it refers to
> the developped sources. This way, I can always
> import in the "official" way and nevertheless all
> my changes are effective immediately.

  i'm not sure how this works, but i will look into it.


> Another approach would be to lay out your package in such
> a way that it refects the installed structure and
> for testing put your script in the directory containing
> your top level packages (or extend "sys.path" with this directory).

  i think that is what i've always assumed that was
how the code is installed is exactly as how i have it
in my development directory as shown above.  your hint
here says that it probably isn't so...  heh...

  thanks, these are things a newbie doesn't know, but
someone experienced just considers common sense.

  for me coming from C code, packed and unpacked via
tarballs and such exactly where i want them to go is
the normal and it seems so strange to find things 
so hard to figure out.

  the other problem i have is that things are cached
and need to be cleared out sometimes before changes are
reflected.  i've run into this multiple times and it's
really yet another frustrating thing.

  i wish there was a way for me to tell python to never
cache anything (while i am developing) anywhere (even
during the setup.py dist/sdist/wheel stuff or insta

Re: Mask two images with python

2018-12-21 Thread ant
Umar Yusuf wrote:
...
> Hello Oscar,
> Thank you for your time.. Here is attached is an example set of the images: 
> https://drive.google.com/file/d/1hyiWswx4GCZQDepXZjktq2zgM_LBbxXt/view?usp=sharing
>  basically, it is "design + mask and glow = result"

  that didn't work for me at all...

  are the images .png or some other format that
allows transparency?

  is it critical that it be done via Python or do you
just want it done at all?  :)

  gimp and other tools (Graphics Magic) will allow 
this to be done interactively or via the command 
line.

  if it has to be done in python i'm only familiar
with pyglet and could do it easily enough that way
(sorry i'm a newbie about other ways in python :) ).

make a sprite in a certain location in a window with
the background image and then make another sprite with
the next layer on top of that one, one at a time, each
with it's own batch id.

then when it appears how you like it you can grab a
screen shot via:


The following example shows how to grab a screenshot of your application window:

pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot.png')

Note that images can only be saved in the PNG format unless the Pillow library 
is installed.
=

  if you want an example of multiple layers i have
my work in progress that does exactly this sort of 
thing (except i never save an image yet - that could
be easily added as above).  you're welcome to take
the code and use it however you like:


  https://salsa.debian.org/ant-guest/gfpoken-in-python


  ant
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Mask two images with python

2018-12-21 Thread Oscar Benjamin
On Fri, 21 Dec 2018 at 09:32, Umar Yusuf  wrote:
>
> On Wednesday, 19 December 2018 19:22:51 UTC+1, Oscar Benjamin  wrote:
> > On Wed, 19 Dec 2018 at 05:42, Umar Yusuf  wrote:
> > >
> > > Hello there,
> > > How do I supper impose an image design on a transparent png image?
> > >
> > > I have tried to use OpenCV's "cv2.bitwise_and" function to no success. I 
> > > posted the detail question here: 
> > > https://stackoverflow.com/questions/53791510/python-opencv-mask-and-glow
> >
> > I don't understand what you're trying to do. Can you show example
> > input and desired output with example numbers? E.g.:
> >
> > mask = [
> > [0, 0, 0, 0],
> > [0, 1, 1, 0],
> > ...
> > ]
> >
> > image = [
> > [12, 32, 45, 56],
> > ...
> >
> > expected_output = ?
>
> Hello Oscar,
> Thank you for your time.. Here is attached is an example set of the images: 
> https://drive.google.com/file/d/1hyiWswx4GCZQDepXZjktq2zgM_LBbxXt/view?usp=sharing
>  basically, it is "design + mask and glow = result"

The reason your question hasn't been answered yet either here or on
StackOverflow is because you need to to take more time to explain it
better. I have suggested above a way to explain it better. If you can
show a clear example of what the input and output pixels are supposed
to be then I'm sure that someone would be able to say how to do it.

>From your description I don't understand unambiguously what you're
trying to do though.

--
Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Mask two images with python

2018-12-21 Thread Umar Yusuf
On Wednesday, 19 December 2018 19:22:51 UTC+1, Oscar Benjamin  wrote:
> On Wed, 19 Dec 2018 at 05:42, Umar Yusuf  wrote:
> >
> > Hello there,
> > How do I supper impose an image design on a transparent png image?
> >
> > I have tried to use OpenCV's "cv2.bitwise_and" function to no success. I 
> > posted the detail question here: 
> > https://stackoverflow.com/questions/53791510/python-opencv-mask-and-glow
> 
> I don't understand what you're trying to do. Can you show example
> input and desired output with example numbers? E.g.:
> 
> mask = [
> [0, 0, 0, 0],
> [0, 1, 1, 0],
> ...
> ]
> 
> image = [
> [12, 32, 45, 56],
> ...
> 
> expected_output = ?
> 
> --
> Oscar


Hello Oscar,
Thank you for your time.. Here is attached is an example set of the images: 
https://drive.google.com/file/d/1hyiWswx4GCZQDepXZjktq2zgM_LBbxXt/view?usp=sharing
 basically, it is "design + mask and glow = result"




-- 
https://mail.python.org/mailman/listinfo/python-list


Side by side comparison - CPython, nuitka, PyPy

2018-12-21 Thread Anthony Flury via Python-list
I thought I would look at a side by side comparison of CPython, nuitka 
and PyPy


*The functionality under test**
*

I have a library (called primelib) which implements a Sieve of 
Erathoneses in pure Python - it was orginally written as part of my 
project Euler attempts


Not only does it build a sieve to test primality, it also builds an 
iterable list of primes, and has functionality to calculate the prime 
factors (and exponents) and also calculate all divisors of a given 
integer (up to the size of the sieve).


To test the primelib there is a simple harness which :

 * Builds a sieve for integers from 2 to 104729 (104729 is the 10,000th
   prime number)
 * Using a pre-built list from primes.utm.edu -
 o For every integer from 2 to 104729 the prime sieve and pre-built
   list agree on the primality or non-primality
 o confirm that the list of ALL primes identified by the sieve is
   the same as the pre-built list.
 o For every integer from 2 to 104729, get primelib to generate the
   prime factors and exponents - and comfirm that they multiply up
   to the expected integer
 o For every integer from 2 to 104729 get primelib to generate the
   divisors on the integer, and confirm that each divisor does
   divide cleanly into the integer

The Sieve is rebuilt between each test, there is no caching of data 
between test cases, so the test harness forces a lot of recalculations.


I have yet to convert primelib to be Python 3 compatible.

Exactly the same test harness was run in all 3 cases :

 * Under CPython 2.7.15, the execution of the test harness took around
   75 seconds to execute over 5 runs - fastest 73, slowest 78.
 * Under Nuitka 0.6, the execution of the test harness after compiler
   took around 85 seconds over 5 runes, fastest 84, slowest 86.
 * Under PyPy, the execution of the test harness took 4.9 seconds on
   average over 5 runs, fastest 4.79, slowest 5.2

I was very impressed at the execution time improvement under PyPy, and a 
little surprised about the lack of improvement under Nuitka.


I know Nuitka is a work in progress, but given that Nuitka compiles 
Python to C code I would have expected some level of gain, especially in 
a maths heavy implementation.


This comparison is provided for information only, and is not intended as 
any form of formal benchmark. I don't claim that primelib is as 
efficient as it could be - although every effort was made to try to make 
it as fast as I could.


--
Anthony Flury
*Email* : anthony.fl...@btinternet.com 
*Twitter* : @TonyFlury 
--
https://mail.python.org/mailman/listinfo/python-list