Forum: Poser Python Scripting


Subject: Using SciPy module in PoserPro2012

an0malaus opened this issue on Nov 13, 2012 ยท 12 posts


an0malaus posted Sat, 21 March 2020 at 2:19 PM

Given that there was a Poser update which did away with my pressing need to interpolate splines to find out the dial value of a parameter with valueOperation influence (the UnaffectedValue() method), I haven't needed SciPy for quite some time. However, that said, the biggest requirement was that the version of NumPy available matched that required by the SciPy module. I'll dig through my howto and post it here.

I'm doing other module inclusions in Poser via the soft link and module.pth method in site-packages (the path differs from Windows to MacOS on where this is). Until we get an update to Python in Poser, (I see beta test notes about Poser Python in Windows getting updated to 2.7.17, which will be useful if it comes to macOS as well) it requires the user to link from an OS level Python 2.7 installation (you can use pip or other package managers there, but pip within Poser Python is completely borked due to its TLS_1.0 protocol use being deprecated and now blocked by all the repository servers since April 2019, IIRC)

Here are my PIL replacement notes for macOS. The essentials will probably be the same for Windows, just the locations will differ.

Procedure to replace Poser Python's bundled PIL module with Pillow, to enable JPEG Image processing.

Having already installed the Pillow package in the macOS python framework, we need to tell Poser where to find it.

In a Finder window, navigate to /Applications/Poser 11/ and select Poser.app (or just Poser, if you haven't set the 
Finder to show hidden file extensions).
Control-Click (or two-finger-click) to bring up the contextual menu and select "Show Package Contents".
Within the current Finder window, navigate to Contents/Resources/site-packages/
In this folder you will see a PIL folder and a PIL.pth file, among other things.
Select the PIL folder, and rename it to 'oldPIL'.
Select the PIL.pth file, two-finger-click (or Control-Click) and choose Duplicate.
Select the PIL.pth file again, and rename it to 'oldPIL.pth'.
Select the 'PIL.pth copy' file, two-finger-click and choose 'Open With' to bring up the sub-menu.
If you see your preferred text editor, choose that, otherwise, choose 'Other ...' and select TextEdit from the dialog.
When the file opens, it should just have 'PIL' in it.
Select the entire line containing 'PIL' and delete it, as we will replace it momentarily.
Switch back to the Finder and open another window from the File menu's New Finder Window option (or press Cmd-N)
Navigate to the place where your macOS python Pillow package is installed. (On my system this is /usr/local/lib/python2.7/site-packages/PIL, so I go to /usr/local/lib/python2.7/site-packages)
Make sure you can see both the 'PIL.pth copy' text editor window and the Finder window with the PIL folder.
Drag the PIL folder from the Finder window to the text editor window and drop it.
That should give you a line similar to '/usr/local/lib/python2.7/site-packages/PIL'
Save the file and Quit the text editor.
In the original Finder window, select and rename the 'PIL.pth copy' file to just 'PIL.pth'
We cannot just Cmd-Option-Drag the PIL folder into Poser.app/Contents/Resources/site-packages, as that creates a MacOS Alias file, which the Finder knows how to resolve, but Python does not, and will be unable to find PIL at all, so we must resort to Unix shell commands to create a soft-link, which looks exactly the same in the Finder, but which Python can successfully traverse to load the PIL package.
In a new Finder window, navigate to the Utilities folder and run (Double-click) the Terminal application.
Copy the following lines and paste them into the terminal window:

cd /Applications/Poser\ 11/Poser.app/Contents/Resources/site-packages/
mv PIL oldPIL
ln -s /usr/local/lib/python2.7/site-packages/PIL
cp -p PIL.pth oldPIL.pth
echo '/usr/local/lib/python2.7/site-packages/PIL' >>PIL.pth

Quit the terminal application.
In your site-packages folder in the Finder, you should now see oldPIL, oldPIL.pth, PIL (with a curved arrow) and PIL.pth, plus whatever was there before.
Use the < button on the Finder window to navigate back out of the Poser.app Contents folder.

You should now be able to launch Poser and properly execute Python scripts which require working JPEG libraries with success.

NOTE: You will have to repeat this process every time you update Poser to a new version, as the installer will probably replace the link you created and the PIL.pth file you edited.

Here's the explanatory comment from the module I built to get dial values using SciPy to interpolate splines prior to UnaffectedValue() being implemented:

 PoserDialValue.py
 (c) 2014,2105 GeoffIX (Geoff Hicks)
 
 This module provides a function to determine (as accurately as possible) the actual dial setting
 of a Poser parameter value. Initial attempts to reverse the affects of ERC influence included in
 the parameter.Value() output were limited to linear regression. It is still not possible to fully
 account for the effect of parameter limit applied discontinuities in the inverse ERC function,
 but the recent exposure to python of parameter ValueOperations() has improved the situation greatly.
 As a consequence of the need to interpolate cubic and higher equations, numpy, scipy.interpolate
 and collections modules must be imported. Scipy is slightly problematic as it is not currently
 bundled with Python 2.7 libraries as used internally by Poser Pro 2014 and thus must be installed
 manually within Poser's python bundle. Note also that the quadratic spline interpolation (3 points)
 is not an accurate replication of Poser's interpolation which is currently undocumented.
 
 Using SciPy with Poser Python 2.7
 
 Procedure to allow PoserPro2012 on OS X to use SciPy python package for spline interpolation
 As determined by GeoffIX (Geoff Hicks) 15th November 2012
 
 *** WARNING: NOT FOR THE FAINT OF HEART ***
 
 Since SciPy relies on NumPy, the version of SciPy must be compiled against a compatible version of NumPy.
 Unfortunately, the NumPy bundled with PoserPro2012 is too old to support the latest builds of SciPy that
 work with the Python 2.7 installation bundled with PoserPro2012 and Mac OSX 10.7/8.
 
 Thus both SciPy and NumPy packages compatible with Python 2.7 need to be built and installed in Mac OS X's
 /Library/Python/2.7/site-packages/ folder
 
 Once that's done, we need to tell PoserPro2012 to use our newer version of NumPy and the SciPy package
 
 Python has several mechanisms to help it locate packages. The relevant one for this operation is the .pth file.
 Poser Python will also locate packages contained within a folder named for the package and containing an __init__.py
 file.
 
 Within the PoserPro2012 Application (Show Package Contents in the Finder) go to Contents/Resources/site-packages
 
 In here you will find a 'numpy' folder with PoserPro2012's bundled numpy package version 1.5.1 or so. This folder
 will need to be renamed ( to oldnumpy or somesuch ) or its existence will override the numpy.pth file we will create.
 
 Create a text file named scipy.pth with the content: (pointing to where you've installed the new scipy module)
 /Library/Python/2.7/site-package/scipy
 
 Create a text file named numpy.pth with the content: (pointing to where you've installed the new numpy module)
 /Library/Python/2.7/site-package/numpy
 
 NOTE:
 Every time you install an update to PoserPro2012, you will need to check whether a replacement numpy folder has been
 created in /Applications/Poser Pro 2012/Poser Pro 2012/Contents/Resources/site-packages to replace the one you
 renamed to oldnumpy and remove it. The installation process does not seem to remove any extraneous files, so the
 numpy.pth and scipy.pth added previously should remain untouched.

[Edited to get rid of the ridiculous monster font caused by the # comment prefix and the old backslash purge insanity in this forum]



My ShareCG Stuff

Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.