ImportError: dynamic module does not define init function (initlibpyuno) - python

I have installed Eclipse IDE with Python, I'm trying to setup an environment for writing some python scripts to automate Libre Office, I have made a script with just one line of code for now ("import libpyuno"), when i run this line of code i get an error:
ImportError: dynamic module does not define init function (initlibpyuno)
I have added "usr/lib/libreoffice/program" as external library path.
Can anyone tell me why I'm getting this error?

The supported way of using pyuno is to invoke the python interpreter bundled with LibreOffice itself. If you want to use an existing interpreter, then you need to make sure you manually do the same setup as the python shell script does inside the LibreOffice installation set (/usr/lib/libreoffice) in your case. This involves not only setting PYTHONPATH but at least specifying URE_BOOTSTRAP as well (both are environment variables.)
Now to your actual question: you probably don't want to import libpyuno. If you want to import a single LibreOffice-specific Python module for testing, then import just uno.
See https://cgit.freedesktop.org/libreoffice/core/tree/scripting/examples/python/NamedRanges.py for a real-world pyuno script, you can see even that only needs the uno module.

Related

What does the python runtime environment mean?

I was reading this article about the sys module in python
And I came across this line:
The sys module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. It allows operating on the interpreter as it provides access to the variables and functions that interact strongly with the interpreter.
Can someone explain what this means? I don't get it
The Python runtime environment is the program that runs your python-scripts.
This program is called 'python' or 'python.exe'
Making a python-program means: Making a script (eg: MyScript.py) that can be fed in the python.exe program.
from the command prompt: python.exe MyScript.py
The sys module can be used in debugging (large) python-scripts.
Good Luck!

Selecting a different python interpreter for every script

I am pretty new to python, interpreters, and programming in general. I script my .py files in pycharm. As you probably know pycharm copies the default interpreter to every project. When I install external libraries I install them at the project interpreter, not at the main interpreter. That works well during the pycharm development phase, but when I try to run the script outside it, it runs it with the default interpreter ( without the newly downloaded libraries ). How can I change that every script uses his own interpreter?
I don't want to download all these libraries to the default compiler and I don't want to change the default library every time I run another script ( via variable editor ).
Also I don't want ro run all my files using pycharm everytime ( since it's quite resource consuming and it takes a while )
I haven't tried anything yet, I couldn't find info about this.
When running without pycharm:
Traceback (most recent call last):
File "C:\Users\Andrei\PycharmProjects\mcdis\mcdis.py", line 1, in <module>
import discord
ModuleNotFoundError: No module named 'discord'
PS: The OS is Windows 10.
I found a shortcut:
Using a shebang ( a line of 'code' that specifies the interpreter which should be used ). While virtual environments seem to have some advantages the shebang trick should do it for most of the scripts.
How to use a shebang :
#!"C:\Users\Andrei\Desktop\MCSERVER\venv\Scripts\python.exe"
Just tell the path to the interpreter with a '#!' in front. Not sure if it works with relative path but I think it does.

PVFoamReader not imported with paraview.simple

I am starting to build python scripts for post-processing OpenFoam-5 results on paraview 5.4.
I was able to record, alter and run scripts inside the paraview interface.
I was also able to run some of these scripts outside of the paraview interface, using both the pvpython and my standart python 2 environment (adding the pvpython libraries folders to the system path).
The problem I am facing now is that when I import paraview.simple, outside of the paraview interface (even if I use pvpython or pvbatch), it loads all the functions and modules but two: PVFoamReader and PVblockMeshReader.
I checked the environment variables and the system path on both shells and they are the same, so I don't know what the issue might me.
I am running the scripts under Ubuntu 16.04
Could somebody help me?
Thank you
I didn't exactly find a solution, but I was suggested a workaround in a CFD-forum.
The workaround is to use the extension ".foam" instead of ".OpenFOAM" and use the paraview.simple function OpenDataFile('foam.foam') the file. The file created should be an empty file on the case directory.

Import Error for BPY module in python

I was trying to write a python script and execute it within blender context. But it reports 'Import Error : No module named "bpy"'. I tried installing another version of blender ( viz. 2.7.6 ) but as it appears there is actually no module named bpy inside "blender-2.76-rc2-win64\2.76\python\lib" , which is the path where python is searching for modules I suppose. I checked out the docs for blender but there is no explicit way of downloading bpy. Any help will be appreciated.
The bpy module is a built-in part of blender that gives python scripts access to the data and operators used in blender. This module is available to scripts run within blender itself, which includes a python interpreter. The bpy module isn't normally available to import from a normal python command, but there is limited support to compile a blender module.
To use the bpy module you can start blender and use the built in python console or you can type in or open a script in the text editor which has a run script button available. Particularly if you run scripts from the text editor you will want access to a console to get error reports.

Python module import fails on website

I have a module (pyScss) I want to use on a remote server (a web host), and since I don't have permissions to install in the usual directory, I installed in a different one (/home/private/lib/python) and modified $PYTHONPATH. Now the trouble comes in trying to import my module.
In the interpreter and on the command line, everything works fine. I can import the module and use it and everything. Even if I say > python -S, I can use site.addsitedir('/home/private/lib/python') and everything works fine.
Now let's say I have a file /home/public/test.py that uses the module scss. Typing > python /home/public/test.py on the command line works, but loading http://mywebsite.com/test.py fails—"No module named scss". The values of sys.path and sys.executable agree in both cases.
What is going on here?

Categories

Resources