Jump to content
Developer Wiki and Function Reference Links ×

PIL (Python Image Library) for VW 2018


DomC

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
Link to comment

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	

 

 

 

 

 

 

Link to comment
  • Marionette Maven
'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.

Link to comment
  • 4 months later...

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
Link to comment
  • 1 year later...

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
Link to comment
  • 3 months later...

Hello

 

I am wondering if there is any documentation for the Marionette function "Marionette.VerifyOrGetLib()" with its posssible parameters. I am wondering if it is possible to get an lib/module and a specific Version with "Marionette.VerifyOrGetLib()" as with pip  (e.g. pip.main('install',  '--upgrade', 'dateutil>=2.5.0') thus not passing a specific ressource URL?

 

I have the problem that for some python lib/modules (e.g. pyspatial or rtree) the pip.main() approach does not work, as on installing those libs/moduls a setup.py call is started an therefore a new instance of VectorWorks.app is started.

 

see my other topic (installing-modules-from-within-a-script) : I am sorry for crosspointing.

 

Many thanks,

 

relume

 

 

 

Edited by relume
Link to comment

Here is the implementation from the Marionette.py

 

def VerifyOrGetLib(missingLib, missingLibURL):
	# try to install user's package
	exit_code = False
	appfolder = vs.GetFolderPath(1)
	appuserfldr = vs.GetFolderPath(12)
	
	cmd = 'Python Externals'
	cmd = appuserfldr + cmd
	
	if not os.path.exists(cmd):
		os.makedirs(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 = 'Python35\Scripts\pip3.exe'
					pathpip = 'Python35\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', missingLibURL, '-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)
							vs.AlrtDialog('Module ', missingLib, ' has been successfully installed.')
				elif  sys.platform == 'darwin':
					import pip
					import shlex
					pos1 = missingLibURL.rfind('/')
					pos2 = missingLibURL.rfind('whl')
					downloadedfile = missingLibURL[pos1+1:pos2] +'whl'
					destination = appuserfldr + downloadedfile
					command_line = "curl -o " + '\"' + destination + '\"' + "  "+ missingLibURL
					args = shlex.split(command_line)
					ret_code = subprocess.call(args)
					if ret_code == 0:
						sys_executable_orig = sys.executable
						sys.executable = '/usr/bin/python'
						ret_code = pip.main(['install', destination,'-q','--target', cmd])
						sys.executable = sys_executable_orig
						if ret_code > 0:
							vs.AlrtDialog('Module ', missingLib, ' cannot be installed.')
							exit_code = False
						else:
							vs.AlrtDialog('Module ', missingLib, ' has been successfully installed.')
							exit_code = True
					else:
						vs.AlrtDialog('Module ', missingLib, ' cannot be installed.')
						exit_code = False
					sys.path.append(cmd+'/')
			else:
				exit_code = False
	except:
		pass	
	return exit_code  

regards,

patrick

Link to comment

Hello Patrick

 

I am sorry to respond only today to your posting.

 

Many thanks for posting the "Marionette.VerifyOrGetLib()" implementation. I previously searched in vain for the Marionette lib/package inside the VectorWorks 2020.app package (MacOS version). Where did you found the Marionette.py file?

 

It is remarkable, that they use for the installation of modules for the MacOS/darwin plattform not the python distro that is installed inside the VectorWorks 2020.app package but the standard python installation :

 

sys.executable = '/usr/bin/python'
ret_code = pip.main(['install', destination,'-q','--target', cmd])
sys.executable = sys_executable_orig
						

On my MacOSX 10.14.6 system "/usr/bin/python" shows version 2.7.16. VectorWorks 2020 has installed version 3.5.2.

 

Furthermore now it became clear to me why installing the modul by pip with an subproccess call and using the value of "sys.executable" did not work and opened a new instance of VectorWorks 2020.app. On the MacOS/darwin plattform "sys.executable" does not hold the path of the internal python installation but the VectorWorks 2020.app itself:

 

/Applications/Vectorworks 2020/Vectorworks 2020.app/Contents/MacOS/Vectorworks

 

For that reason I tried to call directly the internal (VectorWorks 2020.app) python installation to work with it and to have the corresponding python version for installing appropriate modules. But it seems that the internal python installation is not callable and executable:

 

dyld: Library not loaded: /Library/Frameworks/Python.framework/Versions/3.5/Python
  Referenced from: /Applications/Vectorworks 2020/Vectorworks 2020.app/Contents/Frameworks/Python.framework/Versions/3.5/bin/python3.5-32
  Reason: image not found

The call by "subprocess.run('...../bin/python3.5-32', '--version') results for all python bins to "image not found". So I have to assume that for VectorWorks 2020 on the MacOS/darwin plattform the internal python installation and thus the pyhton image (binary) is somewhat "hiden" or maybe compiled into a VectorWorks package (?).

 

For that reason I installed finally for MacOS/darwin with homebrew an appropriate python 3.5.X installation which is then linked and callable to:

 

/usr/local/bin/python3.5

or

/usr/local/bin/pip3.5

thus now I have modified my own modul installation function in order also to use on the MacOS/darwin plattform the now standard subprocess function "subprocess.run" that replace all other previous subprocess functions:

 


vVW_AppUserPy_folder =  vs.GetFolderPath(12).replace(':','/') + 'Python Externals'

vPython_path = '/usr/local/bin/' 
vPython_pip_path = vPython_path + 'pip3.5'

vModule_version = '>=2.5.0' # vModule_version can be passed to pip directly behind the module name
vModule_version = ''

vCommand = [vPython_pip_path , 'install', '--upgrade', '-v', vModule+vModule_version, '--target', vVW_AppUserPy_folder]


vPip_proc = subprocess.run(vCommand, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
vPip_proc_exit_code = vPip_proc.returncode
vPip_proc_sdtout = vPip_proc.stdout.decode('utf-8')
vPip_proc_sdterr = vPip_proc.stderr.decode('utf-8')

 

best regards

 

 

Edited by relume
Link to comment
2 hours ago, relume said:

Many thanks for posting the "Marionette.VerifyOrGetLib()" implementation. I previously searched in vain for the Marionette lib/package inside the VectorWorks 2020.app package (MacOS version). Where did you found the Marionette.py file?

 

No problem, you can find it in  <VW Programfolder>\Plug-Ins\Marionette.vwr\Scripts\.

Just open the VWR with a zip program like 7Zip.

  • Like 1
Link to comment
  • 3 years later...

The path to Marionette.vwr, container of Marionette.py in which in turn resides the definition of VerifyOrGetLib(), in Vectorworks 2023 (VW2023) for Mac is:

 

/Applications/Vectorworks 2023/Plug-Ins/Marionette.vwlibrary/Contents/Resources/Marionette.vwr

 

Edited by Walter Rojas
Punctuation
Link to comment

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.

×
×
  • Create New...