Bug 118503 - Can't run user python macros.
Summary: Can't run user python macros.
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
6.0.4.2 release
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2018-07-02 13:19 UTC by Luis
Modified: 2024-02-14 16:30 UTC (History)
7 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luis 2018-07-02 13:19:33 UTC
Description:
Python macros stored in user profile can't be run.

Steps to Reproduce:
1. Copy sample python script file "HelloWorld.py" from directory share of LO instalation to directory Script/python/ on user profile.
2. Open a new text document.
3. Try to run copied python macro ("HelloWorldPyton") from user location.

Actual Results:
An error message appears:

pyuno._createUnoStructHelper: member 'Context' of struct type 'com.sun.star.uno.Exception' not given a value.


Expected Results:
Inserted text "Hello World (in Python)" in document.


Reproducible: Always


User Profile Reset: Yes



Additional Info:
Tested in windows 7

Versión: 6.0.4.2
Id. de compilación: 9b0d9b32d5dcda91d2f1a96dc04c645c450872bf
Subprocs. CPU: 2; SO: Windows 6.1; Repres. IU: predet.; 
Configuración regional: es-ES (es_ES); Calc: group
Comment 1 Buovjaga 2018-07-15 13:52:32 UTC
No problem for me on Windows or Linux. Tried 6.0.4 and master.
Directory name should be Scripts/python and not Script/python. Then the scripts appear in My Macros.
Comment 2 raal 2018-07-16 21:20:20 UTC
I can confirm with Version: 6.2.0.0.alpha0+ (x64)
Build ID: 7e8dbbb02f25278d5afc51ae4a397831f5b21239
CPU threads: 1; OS: Windows 6.1; UI render: default; 
TinderBox: Win-x86_64@42, Branch:master, Time: 2018-07-15_02:52:05

path C:\Users\user\AppData\Roaming\LibreOfficeDev\4\user\scripts\python
Comment 3 Xisco Faulí 2018-07-17 19:24:03 UTC
@raal, any chance you could try this with previous versions of LibreOffice ?
Comment 4 Luis 2018-07-24 13:47:12 UTC
If case of directory name is not exactly "Scripts/python" (S in uppercase and rest in lowercase) then the python scripts are displayed correctly (files and functions) but don't run and appears the indicated error message.

In my working environment (Windows 7 with PCs conected to domain) the user profile is stored in D: drive so user python scripts are stored in

D:\Usuarios\nombre_usuario\AppData\Roaming\LibreOffice\4\user\Scripts\python

Tested with local user and profile stored in C: drive the issue is not present.
Comment 5 Alain Romedenne 2020-04-24 14:45:40 UTC
Hi Luis, 

Please provide us with the output of the following commands in the Python shell:

import sys
sys.path

HINT
Running the Python interactive console: 
https://help.libreoffice.org/6.4/en-US/text/sbasic/python/python_shell.html
Comment 6 Luis 2020-04-24 21:00:27 UTC
Hi Alain

I am currently working at home. I can't provide the requested information from my corporate environment.
When I can resume work in my office, I will post the information.
Comment 7 Luis 2020-06-30 13:14:08 UTC
Hi Alain:

Test done in my working environment (now windows 10) with recent development version 7.1.0.0.alpha0+ (x86)

Version: 7.1.0.0.alpha0+ (x86)
Build ID: 8ed11b7289533bd609fbcb2adfb7b2982ef6fe22
CPU threads: 4; OS: Windows 10.0 Build 17763; UI render: Skia/Raster; VCL: win
Locale: es-ES (es_ES); UI: en-US
Calc: CL

In this versión if case of directory name is not exactly "Scripts/python" then the python scripts are displayed correctly (files and functions) but the run button is disabled.

The results of the python shell are:

Python 3.7.7 (heads/master-dirty:8ed11b728953, Jun 28 2020, 02:29:02) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', 'D:\\LO7\\program', 'D:\\LO7\\program\\python-core-3.7.7\\lib', 'D:\\LO7\\program\\python-core-3.7.7\\lib\\site-packages', 'D:\\LO7\\program\\python37.zip', 'D:\\LO7\\program\\python-core-3.7.7\\DLLs', 'D:\\LO7\\program\\python-core-3.7.7\\bin', 'D:\\LO7\\program\\python-core-3.7.7']
>>>
Comment 8 Alain Romedenne 2020-08-25 13:35:28 UTC
<UserProfile>/Scripts/python should be appended to Python sys.path in this context
Comment 9 QA Administrators 2022-08-26 03:36:07 UTC Comment hidden (obsolete)
Comment 10 Roman Kuznetsov 2022-09-16 18:27:15 UTC
Alain, so it's a bug or not a bug at all? 

If I understood correctly we have only one place for Python scripts placing and it's just by default. If user want start his/her Python scripts in LibreOffice from any other place then he/she should just add a new place to Python sys.path him/herself, right?
Comment 11 Werner Tietz 2022-11-15 10:41:53 UTC
@Roman:
its not a bug, and your assumptions (and of course @Alains assumptions) are wrong.

sys.path defines the folders where python search for »some_module« if you execute somewhere in your script »import some_module« … nothing else.

but this import-mechanism is almost independent from the generated Dialog in the GUI which populates the available python-functions to the user.
the initial issue was the wrong »…/Script/python/…« instead »…/Scripts/python/…«
Comment 12 Mike Kaganski 2023-08-26 11:35:23 UTC
I tried with Script/python, Scripts/python, and scripts/python, on my Windows 10, using Version: 24.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: c7b59c9484ae6ff88cd8d7017aeb83b02e212c9c
CPU threads: 12; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: en-US
Calc: CL threaded

I expectedly do not see any user scripts in the Python Macros dialog (Tools->Macros->Organize Macros->Python) in the Script/python case; I see the HelloWorld/HelloWorldPython under My Macros with both Scripts/python, and scripts/python; and both of them run OK (producing the respective text in the text document). The path to the python file is C:\lo\src\build\instdir\user\Scripts\python\HelloWorld.py (so on drive C:, testing comment 2), and also I tested with D:\my-test-profile\user\Scripts\python\HelloWorld.py (to check comment 4).

Is it WORKSFORME?