No such thing as a small change PerlMonks

### Inline::Python for windows 10

by tobbes (Acolyte)
 on Oct 15, 2018 at 12:19 UTC Need Help??

tobbes has asked for the wisdom of the Perl Monks concerning the following question:

Greetings. As I am unable to get Inline::Python to compile properly on windows 10. Appearantly it relies on the module Proc::ProccessTable which from what I have heard does not work on windows. Is there an alternative? Or does anybody know if there is a precompiled version somewhere? I am running active state perl and I have not been able to find it in their repo. Any help would be greatly apreciated. OK, I think i may have broken something so I tried reinstalling mingw and clicked everything i could install. Now when I run cpan19> notest install Inline::Python I get this output:

Running install for module 'Inline::Python'
Running make for N/NI/NINE/Inline-Python-0.56.tar.gz
Prepending C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/arch C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/lib C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-
ePu0hw/blib/arch C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-ePu0hw/blib/lib C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/arch C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/lib C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/arch C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/lib C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/arch C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/lib to PERL5LIB for 'get' Has already been unwrapped into directory C:\Perl\cpan\build\NINE-ELKF6g
Prepending C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/arch C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/lib C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-ePu0hw/blib/arch C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-ePu0hw/blib/lib C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/arch
C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/lib C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/arch C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/lib C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/arch C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/lib to PERL5LIB for 'make' 'C:\Perl\bin\perl.exe Makefile.PL INSTALLDIRS=site' returned status 512, won't make
Skipping test because of notest pragma
Running make install
Make had some problems, won't install

Which isn't very helful to me, it seems it is just a general fail to make. Also it says it can't make clean because it is missing a Makefile, which i suppose is bad. I tried downloading the tar and doing the installation manually. appearantly I have a too old version of ExtUtils::MakeMaker

Doing
> upgrade ExtUtils::MakeMaker
or
> install ExtUtils::MakeMaker
results in:
Catching error: "Modification of non-creatable hash value attempted, subscript \"build_requires\" at C:/Perl/lib/CPAN.pm line 9734.\cJ\cI...propagated at C:/Perl/lib/CPAN.pm line 3266.\cJ" at C:/Perl/lib/CPAN.pm line 281. CPAN::shell() called at C:\Perl\bin/cpan.bat line 211
Maybe it's time to give up? Is it at all possible to get cpan to play nicely with windows? I am running perl 5.10 from active state.

Replies are listed 'Best First'.
Re: Inline::Python for windows 10
by syphilis (Bishop) on Oct 15, 2018 at 13:24 UTC
Appearantly it relies on the module Proc::ProccessTable which from what I have heard does not work on windows

The README that ships with Proc-ProcessTable-0.55 confirms that the module doesn't work on native windows (though it does say it will work under Cygwin on Windows).
When I try to build it on Strawberry Perl I get the following errors:
ProcessTable.o:ProcessTable.c:(.text+0x49): undefined reference to OS
+_initialize'
ProcessTable.o:ProcessTable.c:(.text+0x412): undefined reference to O
+S_get_table'
collect2.exe: error: ld returned 1 exit status
[download]
I'm not at all confident that the workaround for windows would be trivial, though I don't really know.

However, according to the Inline::Python-0.56 Makefile.PL, Proc::ProcessTable is needed only for running the test suite.
I would therefore just go ahead and install Inline::Python without bothering about the test suite, and see whether it is functional.

What is the perl -V output for your ActiveState Perl ?

Cheers,
Rob
Re: Inline::Python for windows 10 (update)
by Discipulus (Abbot) on Oct 15, 2018 at 15:24 UTC
Hello tobbes and welcome to the monastery and to the wonderful world of Perl!

> which from what I have heard does not work on windows

is not knoweledge, are rumors.. ;=) but if you want to know how a module, generally speaking, runs out of the box on a OS take a look at cpan testers matrix: matrix for Inline-Python+0.56.

The whole column for windows family is not promising: I tried skipping tests as suggested but I had no success anyway.

# set INLINE_PYTHON_EXECUTABLE=c:\path\to\python.exe

....

dmake.exe:  Error code 129, while making 'blib\arch\auto\Inline\Python
+\Python.dll'
NINE/Inline-Python-0.56.tar.gz
C:\path\strawberry\c\bin\dmake.exe -- NOT OK
Skipping test because of notest pragma
Running make install
Make had returned bad status, install seems impossible
Failed during this command:
JWB/Proc-ProcessTable-0.55.tar.gz            : make NO
NINE/Inline-Python-0.56.tar.gz               : make NO
[download]

Obviously you already have python installed, rigth (and in PATH..)?

My best wishes and share your results!

L*

update I installed active python on another machine: I set the ENV var correctly, I issued force notest install Inline::Python and still fails on the module:

 JWB/Proc-ProcessTable-0.55.tar.gz            : make NO
[download]

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
JWB/Proc-ProcessTable-0.55.tar.gz : make NO

Hmmm ... given that you had specified "notest" and that Proc-ProcessTable is required only for testing, it seems rather ridiculous that the build process should throw up that obstacle.
I would recommend switching to a procedure that bypasses that insanity.

Cheers,
Rob

Maybe try with cpanm --look to manually run the make steps, skipping the tests directly.

cpanm --look Inline::Python
perl Makefile.PL
gmake
gmake install
[download]

Substitute dmake for gmake as needed.

I just tried it, but don't have a python handy that satisfies Inline::Python (it's provided as part of a commercial package) so could not get it to a successful make stage without more work or installing another python on my system.

Re: Inline::Python for windows 10
by dbuckhal (Hermit) on Oct 16, 2018 at 03:16 UTC

If you are willing to use Cygwin on Windows 10, I was able to successfully install Inline::Python on Windows 10 using Cygwin(64bit):

1. Install Cygwin.
2. Using Cygwin Package Manager:
1. Install perl-Inline.
2. Install python and/or python3.
3. Install python3-devel and/or python2-devel.
4. Install libintl-devel (resolves a "mostly harmless" warning message...).
3. From cpan (perl -MCPAN -e shell...)
1. cpan1> get Inline::Python
2. Go to the Inline::Python build directory (~/.cpan/build/Inline-Python-0.56-0).
3. Execute the usual:
4. NOTE: Defaults to "/usr/bin/python" You will need to enter "/usr/bin/python3", manually, if you prefer python3 (See "Use which?" under 'e', below).
perl Makefile.PL
make
make test
make install
[download]
5. $perl Makefile.PL Found these python executables on your PATH: 1. /usr/bin/python Use which? [1] /usr/bin/python3 Using /usr/bin/python3 Using These Settings: Extra Libs: -lintl -ldl Python Lib: -L/usr/lib/python3.6/config-3.6m-x86_64-cygwin -lpytho +n3.6m.dll Includes: -I/usr/include/python3.6m Extra Flags: none (perl Makefile.PL --help for details) Checking if your kit is complete... Looks good Generating a Unix-style Makefile Writing Makefile for Inline::Python Writing MYMETA.yml and MYMETA.json [download] 6. Test 35 will fail due to 'rss' not being available in Windows (See PORTING file under Proc::ProccessTable source). 1. . . . t/31stringification.t ..... ok t/32boolean.t ............. ok t/33reinit.t .............. ok t/34env.t ................. ok t/35dictunicodememleak.t .. Can't access rss' field in class Proc::Pr +ocessTable::Process at t/35dictunicodememleak.t line 28. # Looks like your test exited with 2 before it could output anything. t/35dictunicodememleak.t .. Dubious, test returned 2 (wstat 512, 0x200 +) Failed 2/2 subtests t/cmp.t ................... ok Test Summary Report ------------------- t/35dictunicodememleak.t (Wstat: 512 Tests: 0 Failed: 0) Non-zero exit status: 2 Parse errors: Bad plan. You planned 2 tests but ran 0. Files=37, Tests=838, 12 wallclock secs ( 0.12 usr 0.19 sys + 3.16 cu +sr 7.80 csys = 11.27 CPU) Result: FAIL Failed 1/37 test programs. 0/838 subtests failed. make: *** [Makefile:1061: test_dynamic] Error 255 [download] 7. Rename "t/35dictunicodememleak.t" 8. Tests pass: . . . t/34env.t .............. ok t/cmp.t ................ ok All tests successful. Files=36, Tests=838, 12 wallclock secs ( 0.09 usr 0.22 sys + 2.94 cu +sr 7.37 csys = 10.62 CPU) Result: PASS [download] Testing... $ perl -e '
print "9 + 16 = ", add(9, 16), "\n";
print "9 - 16 = ", subtract(9, 16), "\n";
use Inline Python => <<"END_OF_PYTHON_CODE";
def add(x,y):
return x + y

def subtract(x,y):
return x - y

END_OF_PYTHON_CODE
'

__output__
9 + 16 = 25
9 - 16 = -7
[download]

Hope this helps, because this was a pain to type as appropriately formatted correctly as possible... Whew!

Aaaaand if you choose to say, "Screw Cygwin!", then that is OK, too. :)

Lastly, these steps worked for me, but YMMV...

--Derrick

Unfortunately this is not an option, I did get it to install on linux subsystem as well without doing anything, but I am going to distribute the program I am creating to users and also need to convert it to .exe so cygwin or linux subsystem is not an option unfortunately. But rest assured, I sincearly appreciate the effort :)
Re: Inline::Python for windows 10
by marto (Archbishop) on Oct 15, 2018 at 12:38 UTC

"As I am unable to get Inline::Python to compile properly on windows 10"

What did you try, how did it fail?

Re: Inline::Python for windows 10
by pythonguy (Initiate) on May 29, 2019 at 06:42 UTC

Don't know if this will work for you, but I had luck with the following:

1. Setup
• Windows 10 64-bit
• Strawberry Perl 5.30 64-bit
• Anaconda with Python 3.7 64-bit
2. Add Anaconda to System (not User) Path
• PATH\TO\ANACONDA
• PATH\TO\ANACONDA\Library\mingw-w64\bin
• PATH\TO\ANACONDA\Library\usr\bin
• PATH\TO\ANACONDA\Library\bin
• PATH\TO\ANACONDA\Scripts
• PATH\TO\ANACONDA\bin
• PATH\TO\ANACONDA\condabin
3. Add System (not User) Environment Variable PYTHONHOME=PATH\TO\ANACONDA
4. Run cpanm -n --interactive Inline::Python
• The Makefile.PL seems to have issues finding proper Python info in standard install, so need to do it interactively
• Also want to avoid testing since that relies on Proc::ProcessTable, which isn't available for Windows
• For the python executable path, enter PATH\TO\ANACONDA\python.exe
• For the extra libraries, select default (default = None)
• For the python library, enter PATH\TO\ANACONDA\libs\python37.lib (will change depending on Python version you are using)
• For the python include, enter PATH\TO\ANACONDA\include
5. Open \PATH\TO\STRAWBERRY_PERL\perl\site\lib\Inline.pm
• Windows seems to have write permission issues, so we fix that here
• Find the line with "if ($bin =$FindBin::Bin and"
• Replace it with the following lines:
                $bin =$FindBin::Bin;
chmod 0755, $bin; chmod 0755,$cwd;
if (defined $bin and$bin and
[download]

I haven't had time to check this out with other versions or distributions of Perl/Python, but hopefully this will at least give a starting point. Good luck!

Re: Inline::Python for windows 10
by tobbes (Acolyte) on Oct 17, 2018 at 11:29 UTC
I just realized that I do not know how well Inline::Python would work for me even if I got it installed. I need to distribute my script as a .exe file and I am somewhat dubious as to whether the pythonfiles will be included in the .exe magically. Lilkely the users will have to install Python, which is not an option. It basically leaves me with one option as far as i understand: run perl and python as seperate processes and then use sockets to communicate between them *sigh* that should be simple and stable.

Is there a python equivalent of PAR::Packer? If so then you could embed your packed python exe with the packed perl exe. e.g., something like:

pp --addfile packed_python.exe -o yourtool.exe yourtool.pl
[download]`

In your perl script you would need to find the packed python exe and call it, e.g.:

$python_exe = Path::Class::file ($ENV{PAR_TEMP}, 'inc', 'packed_python.exe');

Your perl script will need to check for \$ENV{PAR_0} to control the use of a packed python exe, otherwise debugging can be a pain, but this can be factored into a sub and the general approach does work.

Addendum - unsurprisingly, there are tools to pack python exes. I have no idea if these work, but this link looks handy at first glance: https://medium.com/dreamcatcher-its-blog/making-an-stand-alone-executable-from-a-python-script-using-pyinstaller-d1df9170e263

at some point you need to ignore "packers" and just distribute a big'ol zip file

You can't rewrite your python in perl, or vice versa?

Log In?
 Username: Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1224037]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2019-10-18 01:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In 2019 the site I miss most is:

Results (44 votes). Check out past polls.

Notices?