DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Python not working

Solved!
Go to solution

   I followed the guide (https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000wxMvCAI&l=en-US) and the Python import is still not working.
   
   I have a virtual environment of Python 3.6.3 64 bit (somewhere in docu there is mentioned support of python 3.6 and 3.7). I insalled the PYwin32 package into this environment. I added the path to the __venv__ and __venv__\Scripts to the PATH variable. I executed DIADEM as administrator.
   
   For python path in DIAdem I tried:
   path to python.exe => Scripts work, but point to the original DIAdem python, without access to my libraries, e.g. numpy.
   path to Scripts folder containing python.exe => DIAdem crashes instantly without any error message when running the script.
   path to __venv__ folder containing Scripts folder => DIAdem shows an error message, that the python failed to initialise.
   
   My comments:
   It would be nice if there was a better explanation of "Add Python installation path to DIAdem settings." in the guide. As mentioned above, I could think up 3 different paths, none of whose worked for me.
   It would be good if DIAdem showed some more meaningful message than just "Initializing Python has failed". This one is not very helpful for debugging.
   
   Can you tell me, what should I try next to make python working in DIAdem?
   
   I suppose I do not have to add the sys.path.append() command to the script, when I just want to use the packages from my virtual environment, correct? When a correct environment is executed, all of its packages should be available.

0 Kudos
Message 1 of 5
(2,912 Views)
Solution
Accepted by topic author SeryDavid

Hi SeryDavid,

 

I have ran DIAdem with Python scripting quite a bit.  But I set it up a little different than what I read your process to be.

 

My process:

1) I installed python to a path like c:/python/python365

2) Did not use VEnv or any other virtual environment. Seems that option to use Virtual environments is not supported in 2020.( NI can weigh in on this, I have asked for this in post)

3) Install pywin32 to this python directory. and verity that can issue import pywin32 and this works in ldle. (Sometimes have to install this from installer, and other times a python -m pip install pywin32 will work. I have to watch this sometimes)

4) Install what every package you like into this install of python.  For my use, I use this command process:

4.1) Open command window, And Cd to the c:\python\python365 (Location were python.exe is located)

4.2) Issue the command  "python  -m pip install numpy"

This will install to the the c:/python/python365 directory. and should put in path  c:/python/python365/lib/site-packages

4.3) Now should be able to run in c:/python/python365/python.exe and be able to issue import numpy as np

 

then in DIAdem  you will need to set the path to python in settings qui below.

Then save the settings to a new both diadem.ddd. and for me I also save to diadem_py.ddd. That way I can have a DIAdem_vbs.ddd and a DIAdem_py.ddd.    This allows me to switch between the two scripting options by reloading ddd file.

 

It also allows you to have two DIAdem instances running. One in VBS scripting and Second in python scripting. this I find is a productive environment. (I also use Pycharm for heavy python development. VS code is also pretty good)

 

Hopefully this will get you up and running in DIAdem with python scripting option.

 

Paul

 

ps. Note: DIAdem does not require that python instance used be on the path in any sense, it just requires that you give the path to the python.exe file that you want to use.  It will reference what packages that python.exe has in its /lib/site-packages directory under the path to python.exe.  So I have a c:\python\python36_diadem\ path for just for DIAdem, that way can control the packages somewhat.

 

 

Pesmith8_0-1597402460959.png

 

 

0 Kudos
Message 2 of 5
(2,848 Views)

Hi Guys,

 

Thanks Paul for you excellent answer, as usual.  I just want to confirm that DIAdem 2020 does NOT support virtual python environments.  I have communicated to DIAdem R&D that this would be a very desirable feature for python-savvy customers to have, but it is not currently implemented.  For the time being you'll have to work with python engines, each installed to a dedicated folder that is registered with the OS.  The path to that registered folder, with a trailing backslash (DIAdem standard) is what you enter into the DIAdem SCRIPT settings field.  For others looking at this, remember to save the *.DDD file after making that change and restarting DIAdem.

 

Brad Turpin

Principal Technical Support Engineer

National Instruments

0 Kudos
Message 3 of 5
(2,839 Views)

Thanks for the reply. Using a complete installation instead of a virtual environment worked without any issues.

 

It would be nice though if it was at least mentioned in the official documentation that the virtual environments are not supported. Currently it is quite a standard way to work with virtual environments when developing a python application, so there will probably be more users with similar issue.

0 Kudos
Message 4 of 5
(2,818 Views)
Hi Brad, is this still the case with Diadem 2021 version or has this been changed now?
0 Kudos
Message 5 of 5
(1,831 Views)