PDA

View Full Version : Using Python modules



lianjasupport
2012-04-03, 20:01
Where do I need to copy Python modules to so I can use them in my Python code in Lianja?

Cox
2013-11-16, 17:56
Please advice on how I can make use of Python to access/determine the serial number of a USB drive.
I am aware that I can make use of microsoft WMI (Windows Management Instrumentation) but I stumble on how to perform the imports of the modules required. The resources I am looking at is http://timgolden.me.uk/python/wmi/index.html This shows need to use pywin32 that is where I can't figure out how to add to Lianja.

barrymavin
2013-11-16, 21:07
Hi Cox,

C:\lianja\scriptinglanguages\python\Lib

This is the path used by python which is setup in the registry when you install Lianja.

HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.7\ PythonPath
C:\lianja\scriptinglanguages\python\Lib;C:\lianja\ scriptinglanguages\python\DLLs;C:\lianja\scripting languages\python\Lib\lib-tk

Cox
2013-11-20, 06:52
I am trying to run a for in range loop python as follows via a command

for num in range(5):
Lianja.writeLog(num)

p.s, there is a tab before th Lianja.writeLog.


not getting any output in the log.
running RC10

barrymavin
2013-11-20, 07:50
Hello Cox,

Try it from the python tab in the console workspace.

yvonne.milne
2013-11-20, 08:09
Hi,

Lianja.writeLog() takes a string.

Regards,

Yvonne

Cox
2013-11-26, 09:16
I have managed to gather system details using python & vbscript and during this exercise, found that I did need to make use of modules that are not default in the lianja distribution (hence moved to next solution). Could a breakdown on how this is achieved be put forward please since copying a given directory into the python/lib didn't work for me.
Most of the documentations talked about installing the module to the current python on system, but as a distributed python, couldn't figure this out.

Of interest was pywin32.

http://sourceforge.net/projects/pywin32/

Need: To get unique serial number (Manufacture number) associated with a USB key.

yvonne.milne
2013-11-26, 11:58
Hi Cox,

I was able to use the msi installer for pywin32, but I had to change a couple of the Registry entries created by the Lianja for Python to do so. (I'll get these checked out for final release.)

I'm on Win64, so I have:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python

on Win32 the root will be (applies to the entries that follow):

HKEY_LOCAL_MACHINE\SOFTWARE\Python

The Lianja installer puts InstallPath here:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\Pyt honCore\InstallPath

but I think it should be one level lower, i.e.

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\Pyt honCore\2.7\InstallPath

and the (Default) string value it contains should be the python folder under Lianja. For a default installation, this is:

C:\Lianja\scriptinglanguages\python\

Also, this:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\Pyt honCore\2.7\InstallPath\InstallGroup

should have the (Default) string value of:

Python 2.7

Regards,

Yvonne

Note: the Forum editor is adding a space in 'PythonCore' - there should be no space.

Cox
2013-11-27, 15:16
Please see images, I have made the registry changes as shown,

483
and tried to install WMI-1.4.9.win32 (https://pypi.python.org/pypi/WMI/#downloads). as shown in the install pane, the entry for installation directory is as follows (C:\Lianja\scriptinglanguages\python\Lib\site-packages\)
484

Have tried at the console to run

import wmi, but getting error



Wed 27. Nov 21:12:30 2013
**** Lianja Python error ****
Traceback (most recent call last):
File "Console" at line 1, in <module>
File "C:\Lianja\scriptinglanguages\python\lib\site-packages\wmi.py" at line 88, in <module>
from win32com.client import GetObject, Dispatch
ImportError: No module named win32com.client

yvonne.milne
2013-11-28, 06:51
Hi Cox,

It looks like you don't yet have pywin32 installed and wmi sits on top of it. Once you have pywin32 installed, copy the dlls from C:\Lianja\scriptinglanguages\python\Lib\site-packages\pywin32_system32 into your Windows System folder and you should be up and running.

Regards,

Yvonne

Cox
2013-11-28, 14:00
Thanks, that sort it. just needed to add the dll's to systems directory. Just to confirm now that a published application when moved to a new machine will have these covered...

yvonne.milne
2013-11-29, 07:15
Hi Cox,

Calling the following as administrator, should also do it (default Lianja installation path used here):


cd c:\lianja\bin
c:\lianja\scriptinglanguages\python\python c:\lianja\scriptinglanguages\python\scripts\pywin3 2_postinstall.py -quiet -install

Regards,

Yvonne