Support Forum

Use Python LayoutScript from external editor

User
20190504
Thursday 25th October 2018
Hello, I have try many things to get the Python "LayoutScript" to work on Windows 10 in an external editor, but I always end up with this error: ImportError: DLL load failed: The specified module could not be found. The help site is saying that it is possible. What should I do? Regards, Guillaume
Jürgen
LayoutEditorFull
Thursday 25th October 2018
Yes that is possible. Starting Python with the verbose option will should show you which DLL file is not found. All DLLs the LayoutEditor/Layoutscript need are located in the *layout/bin* folder within the LayoutEditor package. Adding this folder to the PATH environment variable usually fix this problem. Also the PYTHONPATH and PYTHONHOME environment variable had to be set correctly so that the LayoutScript plugin is found. By calling python from the integrated text editor these three environment variable are set according the current installation.
User
20190504
Thursday 25th October 2018
Wow. That was a fast response. Thanks! However, I'm not sure I understand. By the *layout/bin* folder, do you mean this folder "C:\Program Files (x86)\LayoutEditor\bin"? Regards, Guillaume
Jürgen
LayoutEditorFull
Thursday 25th October 2018
Yes, exactly that folder. The exact location may be different on other Windows version or in case your use the ZIP package of the LayoutEditor. On Linux system you need to set LD_LIBRARY_PATH instead of the PATH environment.
User
20190504
Friday 26th October 2018
I have set all the environment variables (in a Python virtual environment), but I still have the same problem : ``` >>> import os >>> os.environ["PATH"] 'C:\\Users\\guillaume\\.virtualenvs\\tests-9V1X_VNr\\Scripts;C:\\Program Files (x86)\\LayoutEditor\\bin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Program Files\\Microsoft MPI\\Bin\\;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x86;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x64;C:\\Program Files\\MATLAB\\R2017b\\runtime\\win64;C:\\Program Files\\MATLAB\\R2017b\\bin;C:\\Program Files (x86)\\Druide\\Antidote 9\\Application\\Bin64\\;C:\\Program Files (x86)\\Druide\\Antidote 9\\Application\\Bin32\\;C:\\Users\\guillaume\\AppData\\Local\\Continuum\\anaconda3;C:\\Users\\guillaume\\AppData\\Local\\Continuum\\anaconda3\\Library\\mingw-w64\\bin;C:\\Users\\guillaume\\AppData\\Local\\Continuum\\anaconda3\\Library\\usr\\bin;C:\\Users\\guillaume\\AppData\\Local\\Continuum\\anaconda3\\Library\\bin;C:\\Users\\guillaume\\AppData\\Local\\Continuum\\anaconda3\\Scripts;C:\\Users\\guillaume\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\guillaume\\AppData\\Local\\atom\\bin;' >>> os.environ["PYTHONHOME"] 'C:\\Users\\guillaume\\.virtualenvs\\tests-9V1X_VNr\\Scripts' >>> os.environ["PYTHONPATH"] 'C:\\Users\\guillaume\\.virtualenvs\\tests-9V1X_VNr\\Lib\\site-packages;C:\\Users\\guillaume\\.virtualenvs\\tests-9V1X_VNr\\Lib;C:\\Users\\guillaume\\.virtualenvs\\tests-9V1X_VNr\\Scripts;C:\\Program Files (x86)\\LayoutEditor\\python;' ``` I have even added `LAYOUTEDITORPYTHONLICENSE` and `PYTHONIOENCODING`, but it doesn't change anything. Am I missing anything? Regards, Guillaume
Jürgen
LayoutEditorFull
Friday 26th October 2018
I think, if you change the PATH environment inside Python you will only effect the path settings for calls you make from that Python instance and not for the current running instance of Python. You need to set the environment before starting Python for example with a batch script like: batch file example ``` set "PATH=C:\Program Files (x86)\LayoutEditor\bin;%path%" python -vvvv ```
User
20190504
Friday 26th October 2018
The environment variables where set before opening python. I have attached the output of python in verbose mode when I try to import LayoutScript. https://pastebin.com/bUnb5e8v Best regards, Guillaume
Jürgen
LayoutEditorFull
Friday 26th October 2018
This batch script will run the shipped Python package: ```` set "PATH=C:\Program Files (x86)\LayoutEditor\bin;%path%" set "PYTHONPATH=C:\Program Files (x86)\LayoutEditor\python;C:\Program Files (x86)\LayoutEditor\python\python35\lib;C:\Program Files (x86)\LayoutEditor\python\python35\lib\site-packages" set "PATHHOME=C:\Program Files (x86)\LayoutEditor\python" "C:\Program Files (x86)\LayoutEditor\python\python35\python.exe" ```` According your error messager the file *_LayoutScript.pyd* is not found. It is located at "C:\Program Files (x86)\LayoutEditor\python\".
User
20190504
Friday 26th October 2018
Well this works. I can at least use another editor. However, I was hoping to be able to do more than that. I had hope that I could use a more recent version of python (right now, my system version is at 3.7) or, at least, if I was stuck on 3.5, to be able to install 3rd party package (numpy for instance). I have tried to install 3rd party package with `pip` from the python bundle with LayoutEditor, but it fails... I have tried to use another instance of python 3.5, but I'm not able to import LayoutScript. I get an error about Qt and python crash. Was the python bundle with LayoutEditor modified in some way from the upstream? Best regards, Guillaume
Jürgen
LayoutEditorFull
Friday 26th October 2018
That is a unmodified python package downloaded from the python website. The LayoutScript python module should work with any other python 3.5 package. However i expect that it does not work with python modules using a different version of Qt.
User
20190504
Friday 26th October 2018
I have moved the `C:\Program Files (x86)\LayoutEditor\python\python35` somewhere else to be able to install third party packages, because in its original location it requires administration privilege and it works. However, if I try to import LayoutScript, I get the same message that I got when I was using another instance of python 3.5. ``` This application failed to start because it could not find or load the Qt platform plugin "windows" in "". Reinstalling the application may fix this problem. ``` Any idea on how to fix this? Best regards, Guillaume
Jürgen
LayoutEditorFull
Friday 26th October 2018
The Qt library use plugins itself. These plugins are shipped with the LayoutEditor inside the *bin* folder and named *platforms*, *imagesformats* and *printsupport*. In your case these plugins are not found by the Qt library. Copy these folders next to the python.exe may help. Also the Qt library documentation listed some ways to tell Qt where the plugins can be found.
User
20190504
Monday 29th October 2018
I finally manage to make everything work pretty much the way I wanted... Thank you, very, very, very much, Jürgen!!! For the record, here is what I had to do: I copied the `bin` and `python` folders from the `LayoutEditor` folder to another location on my computer. This is done to be able to install 3rd party python packages. Otherwise, administrator privilege is required. The `bin` folder has to be moved, because `LayoutScript` has to be able to find the Qt DLLs (I think). In the bin folder, I have kept all folders and removed every files that do not start with "q". For the environment variables, I have set them in a batch file : ```batch set "PATH=*original LayoutEditor bin folder*;*new python35 folder location*; *new python35/Scripts folder location*;%path%" set "PYTHONPATH=*original LayoutEditor python folder*;*new python35/Lib folder location*; *new python35/Lib/site-packages folder location*;" ``` As far as I know, the `PYTHONHOME` environment variable doesn't change anything. With this setup, I can install 3rd party package easily and import `LayoutScript` without errors. This enables me to use the Python IDE of my choosing. It was a pain to setup, but now I will be able to be more productive. If I had an improvement recommendation for LayoutEditor, it would be to ease the `LayoutScript`'s integration with other editors. The holy grail would be to be able to install LayoutEditor, do a `pip install LayoutScript` and be able to code right away (without having to move anything around an fiddle with environment variables). Thanks again for your help! Regards, Guillaume