Jump to content
DomC

PIL (Python Image Library) for VW 2018

Recommended Posts

Hi

Anyone got the PIL Auto-Library-Installer got to work with 2018?

 

I am testing with this Python-Vectorscript on Mac Sierra:

#Python Script

import Marionette
PillowPath = 'https://pypi.python.org/packages/c0/53/744c1127f0fa988c742f9db6615127125f993da8324e3126b3d769947fc0/Pillow-4.0.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl'
Marionette.VerifyOrGetLib('PIL', PillowPath)

I think maybe this installer package is not for sierra ...

A strange thing happens, if I run the script (Or run it in a Marionette Node, it's the same): My Vectorworks starts a 2nd time while the original Vectorworks freezes

 

All other other tested Packages works fine:

ShapelyPath = 'https://pypi.python.org/packages/83/38/67f9826a0e6ac8e3dbf9207b1e30f6e74f042e8a4ff0a958fb113ef81d12/Shapely-1.6.2.post1-cp35-cp35m-macosx_10_9_intel.macosx_10_9_x86_64.whl#md5=ab1afb53f6ba7f0b26f24e2c8485dced'
matplotlibPath = 'https://pypi.python.org/packages/ca/3a/ed9fdea2d54d5d547ef24d98da5ad4354754e10cbc2e4159a29cb44d0b8a/matplotlib-2.1.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl'

Also Scipy, Numpy

 

Why of all things "Pillow" :-(  Is there any alternative?

 

 

 

Edited by DomC

Share this post


Link to post

Have you tried python -m pip install pillow? If successfully installed, you can see what version of pillow it tried to install.

 

Share this post


Link to post

Hi

Thanks for Input. I can install PIL from external python package. Even I can copy/paste PIL 3.0.0 from my 2017 user Folder and it works. I think embedded python version in 2018 is 3.5 ..

 

So far it makes no sense to use external moduls in Marionette nodes  if users have to install them manually. The task is to check and install the module inside the node with the embedded python. I am sure, there are ways to do the installation with a subprocess or by changing something in the Function or by updating something inside the embedded python.

 

An installer routine for external python modules in Marionette nodes is something, which already exists. I tried with some options like '--verbose' (detailed error log) etc. from the PIP Documentation here:

https://pip.pypa.io/en/stable/reference/pip/

 

Could be everything. From a user Error (wrong package, wrong url) over a Bug in PIL,  an Installer Bug to a Vectorworks incompatibility ...

I played around with the Marionette Module checker (With this code as a simple Script it do not crash and I was able to play around with some parameters)

I think I should stop investing my time for that issue. 

 

The Error log:

5a08b64229482_PILinstallationlog.thumb.png.5aea1a96f8e0069973b162870ccfb9d9.png

The most interesting code line:

ret_code = pip.main(['install', appuserfldr + downloadedfile, '--target', cmd ]) 

 

The Module Installer:

 

import vs
from collections import OrderedDict
import operator
import copy
import  os, sys, subprocess, urllib.request, importlib, logging
exit_code = False
appfolder = vs.GetFolderPath(1)
appuserfldr = vs.GetFolderPath(12)
cmd = 'Python Externals'

missngLibURL = 'https://pypi.python.org/packages/c0/53/744c1127f0fa988c742f9db6615127125f993da8324e3126b3d769947fc0/Pillow-4.0.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl'
#missngLibURL = 'https://pypi.python.org/packages/8b/aa/e62f29194562a58f1e1e4158899bb0e33052db824c08e0eb7ea806315b61/Pillow-3.0.0-cp33-cp33m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl'

missingLib = 'PIL'
#https://pip.pypa.io/en/stable/reference/pip/#general-options


if sys.platform == 'win32': 
	cmd = appuserfldr + cmd
elif  sys.platform == 'darwin':
	pos = appfolder.find(':')
	appfolder = appfolder[pos:]
	appfolder = appfolder.replace(':','/')
				
	pos = appuserfldr.find(':')
	appuserfldr = appuserfldr[pos:]
	appuserfldr = appuserfldr.replace(':','/')
	cmd = appuserfldr + cmd
if not os.path.exists(cmd):
	os.makedirs(cmd)
sys.path.append(cmd)
try:	
	try:
		importlib.import_module(missingLib)
		exit_code = True
	except ImportError:
		#show dialog here
		question = 'Python module ' + missingLib + ' is not installed. Would you like to download and install it now?'
		res = vs. AlertQuestion(question,'', 1,'','','','') 
		if res == 1 :
			if sys.platform == 'win32': 
				piploc = 'Python33\Scripts\pip.exe'
				pathpip = 'Python33\Scripts'  
				cdpath = os.path.join(appfolder, pathpip)
				cmdpip = os.path.join(appfolder, piploc)
				wd = os.getcwd()  
				if os.path.exists(cmd) and os.path.exists(cmdpip):
					os.chdir(cdpath)
					ret_code = subprocess.call([cmdpip, 'install', missngLibURL, '-t', cmd ])
					if ret_code > 0:
						vs.AlrtDialog('Module ', missingLib, ' cannot be downloaded.'); 
						exit_code = False
					else:
						exit_code = True
						sys.path.append(cmd)
						os.chdir(wd)
			elif  sys.platform == 'darwin':
				import pip
				import urllib.request
				pos1 = missngLibURL.rfind('/')
				pos2 = missngLibURL.rfind('whl')
				downloadedfile = missngLibURL[pos1+1:pos2]
				downloadedfile = downloadedfile+'whl'
				urllib.request.urlretrieve(missngLibURL, appuserfldr + downloadedfile)
				#vs.Message(str(downloadedfile))
				ret_code = pip.main(['install', appuserfldr + downloadedfile, '--target', cmd ]) 
				# original Line ret_code = pip.main(['install', appuserfldr + downloadedfile, '-q', '--target', cmd ])
				if ret_code > 0:
					vs.AlrtDialog('Module ', missingLib, ' cannot be downloaded.');
					exit_code = False
				else:
					exit_code = True
				sys.path.append(cmd)
		else:
			exit_code = False
except:
	pass	

 

 

 

 

 

 

Share this post


Link to post
'https://pypi.python.org/packages/13/3e/cb24be6c222138c7d2028502cd2be3b7bec3592456a01c9450bb0f7be641/Pillow-4.2.1-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl#md5=28c49cafcd80b160494e3628b8148e0d'

 

The above path is the path I have been using for Mac.

My Mac is giving me a hard time right now, but might be worth trying this path instead? Hopefully I can get my computer running well enough to double check.

Share this post


Link to post
Quote

The above path is the path I have been using for Mac.

 

Negative ... I use Vectorworks 2018 SP1 German Version. Mac OSX 10.12.6. Same issue with the above url.

 

 

Share this post


Link to post

Hello

 

I wanted to install  the "pandas"  library and found problems using the Marionette.VerifyOrGetLib() function but also with the above script from DomC that is similar to the Marionette.VerifyOrGetLib() function. Further for both functions/scripts an URL to a specific version of library to be installed is needed. But pip.main() has the possibility to get the right library version for the VectorWorks Python environment (acutally in VW2018 is 3.5.2). I was able to install the library "numpy" with the following command :

 

pip.main(['install', 'numpy', '--target', vPathToMy_VW_PythonExternals_Folder])

But this did not work for the library "pandas" as the appropriate pip.main() command rised an error saying that there is no correct matching version. But by passing an "-q" parameter "pandas" installs correctly:

 

pip.main(['install', 'numpy', '-q', '--target', vPathToMy_VW_PythonExternals_Folder])

 

Then I tried also to install "pillow" and it installed also correctly (version 5.0.0) with all dependencies. But there is some problem with probing for correct installation. While the lib distribution is called "pillow", the name to retrieve it with pip.main(),  testing the existence and for importing the lib has to be named "PIL". For this reason Morionette.VeriyOrGetLib() does not work. So the installed lib "pillow" has to be tested and imported by:

 

importlib.import_module('PIL')

 

So a script that encompass this problem could be as this:

 


import os
import sys
import importlib
import vs


appfolder = vs.GetFolderPath(1)
appuserfldr = vs.GetFolderPath(12)
cmd = 'Python Externals'


if (sys.platform == 'darwin'):
	pos = appfolder.find(':')
	appfolder = appfolder[pos:]
	appfolder = appfolder.replace(':','/')
				
	pos = appuserfldr.find(':')
	appuserfldr = appuserfldr[pos:]
	appuserfldr = appuserfldr.replace(':','/')
	cmd = appuserfldr + cmd

vs.AlrtDialog("path : " + cmd)
	
if not os.path.exists(cmd):
	os.makedirs(cmd)


#libToimport = 'numpy'
#libToimport = 'pandas'
libToimport = 'pillow'
libToimportAlias = 'PIL'



try:
    importlib.import_module(libToimportAlias)
except ImportError:
	import pip
	pip.main(['install', '--upgrade', '-q', libToimport,  '--target', cmd ])

	importlib.import_module(libToimportAlias)


try:
	importlib.import_module(libToimportAlias)
	exit_code = True
	vs.AlrtDialog('is installed : '+ libToimport)

except ImportError:
	vs.AlrtDialog('not installed : '+ libToimport)

 

Best regards

 

 

P.S. And not to forget to reference the python search path to "~/Library/Applications Support/VectorWorks/.../Python Externals"

 

 

 

 

 

Edited by relume

Share this post


Link to post

Hi

This thread is a little older. I just had to install pandas and it worked with the following script (VW 2020). Not tested on Windows. Newer Versions of pandas maybe possible but some of them requires python 3.5.3 and we have 3.5.2 embedded in Vectorworks

 

import sys
import Marionette
import platform
import os

Usr = vs.GetFolderPath(-12)
(major, minor, maintenance, platform, buildNum) = vs.GetVersionEx()
if platform == 1:
	Path = Usr + 'temp/tempImg.png'
else:
	Path = Usr + 'temp\\tempImg.png'


vs.AlrtDialog(str(sys.version))
if platform == 2:
	pandas = 'https://files.pythonhosted.org/packages/9f/df/6718044777d8a76532cb219a7604606e784bf630fe724a3fec2000ce31b1/pandas-0.21.0-cp35-cp35m-win_amd64.whl'
else:
	pandas = 'https://files.pythonhosted.org/packages/69/c2/0323c5bdb0d0b8b9e07dc96e81fb13155784a4b2d5cb1feaa110261e5ae3/pandas-0.21.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl'

if Marionette.VerifyOrGetLib('pandas', pandas):
	pass
else:	
	vs.AlrtDialog('Modul pandas ist bereits installiert')
	

 

Edited by DomC
  • Like 2

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...