PVFoamReader not imported with paraview.simple - python

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.

Related

How to integrate ns3 module with pycharm?

I'm new to the ns3, and I was trying to integrate ns3 to PyCharm cause I'm familiar with PyCharm. It seems that ns3 is installed correctly on my machine, running ./waf python works fine but when I use ./waf shell, there are some modules it couldn't find, such as ns.application...etc. So, when I try the solution on this page: add waf libraries to PyCharm, it doesn't work too. Could anyone help me to solve this issue? I would really really appreciate it. By the way, the file I test was the sample from ns3: ns3_root/source/example/tutorial/first.py.
If you have enabled the python bindings and have built them, you need to add the ns3_root/build/bindings/python to the environment variable PYTHONPATH. After that running first.py should work.
You can do that running
export PYTHONPATH=$PYTHONPATH:/path/to/ns3_root/build/bindings/python
Or select first.py, edit the target settings and add that environment variable.
Or if you want this to persist, add this line to the end of the ~/. bashrc file.

Install modules in Python locally to script

I have the following problem:
I have to run some test/diagnostic Python script on a Windows system. Due to explicit requirement, the system has no default system-wide Python instance, but there are two different Python instances installed, used locally by applications running on the system. However, both these instances lack some basic modules my script uses (like logging, urllib, configparser etc.).
I want to run %PYTHONPATH%\python.exe myscript.py where %PYTHONPATH% points to one of the installed Python instances, but install the required additional modules "somewhere" outside %PYTHONPATH% (preferrably, in the same directory where my script is installed) so that my script can use them.
As my script is a test tool, it should not modify the OS or installed software, so the Python installation under %PYTHONPATH% should not be changed in any way.
It is also expected that the installation can be fully automated, ie. the best way to install would be just have the modules in the same .zip file with my script which is unpacked onto the target path.
It is also important that the system has no Internet access, so I have to download required files on another machine and copy them to the target system.
Can you guide me how to do it?
I found an answer myself - it is quite simple:
obtain the zip file containing standard modules from the appropriate Python version distribution (in my case it was the file python38.zip, it is inside the main zip file downloadable from Python site)
Unpack the contents of this file to c:\mydir\Python38\site-packages, where c:\mydir is the directory containing my script
set the environment variable PYTHONUSERBASE=c:\mydir before running my script
Now I can run the script and it finds all "missing" standard modules in c:\mydir\Python38\site-packages.
I think what youy are seeking for is a python virtual environment.
( internet needed )
Check :
https://docs.python.org/fr/3/library/venv.html
Then for the installation, you can creat a .exe file containing all dependencies.
(no internet needed)
Check:
https://www.pyinstaller.org/

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

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.

What is the purpose of the environmental variable PYTHONPATH

On windows 7, I currently don't have a python path. Can I safely make one? If so, how do I do it?
Upon making this variable, I can no longer load Spyder (IDE) without it crashing. Does anyone know why?
I would like to edit my existing python path if possible, but just don't know why it isn't already there in environmental variables.
I would ultimately like to be able to run "python myscript.py" and have myscript be in a different directory from the call directory.
PYTHONPATH adds new paths to the ones Python uses by default. The path in total determines where Python will look for modules when you import them.
Look at sys.path to see the combination of the defaults with your PYTHONPATH environment variable. It's likely that Spyder is loading a module that exists in two different places and the wrong one comes first.
When you import modules in python, python searches for the module in the directories in PYTHONPATH, in addition to some other directories.
In order to be able to run your script as > myscript.py, you want to put your script somewhere on PATH (here are some instructions for viewing or updating PATH), this is where the OS looks for scripts and programs when you give it a command. I believe that in windows the .py extension must be associated with python for windows to know that myscript.py should be run using python. This should happen automatically when python in installed, but maybe someone with more windows knowledge can comment on this.
it has role similar to path. this variable tells the python interpreter where to
locate the module files imported into a program. it should include the python source library directory and the directories contain in python source code

How to deploy Python to Windows users?

I'm soon to launch a beta app and this have the option to create custom integration scripts on Python.
The app will target Mac OS X and Windows, and my problem is with Windows where Python normally is not present.
My actual aproach is silently run the Python 2.6 install. However I face the problem that is not activated by default and the path is not set when use the command line options. And I fear that if Python is installed before and I upgrade to a new version this could break something else...
So, I wonder how this can be done cleanly. Is it OK if I copy the whole Python 2.6 directory, and put it in a sub-directory of my app and install everything there? Or with virtualenv is posible run diferents versions of Python (if Python is already installed in the machine?).
I also play before embedding Python with a DLL, and found it easy but I lost the ability to debug, so I switch to command-line plug-ins.
I execute the plug-ins from command line and read the STDOUT and STDERR output. The app is made with Delphi/Lazarus. I install others modules like JSON and RPC clients, Win32com, ORM, etc. I create the installer with bitrock.
UPDATE: The end-users are small business owners, and the Python scripts are made by developers. I want to avoid any additional step in the deployment, so I want a fully integrated setup.
Copy a Portable Python folder out of your installer, into the same folder as your Delphi/Lazarus app. Set all paths appropriately for that.
You might try using py2exe. It creates a .exe file with Python already included!
Integrate the python interpreter into your Delphi app with P4D. These components actually work, and in both directions too (Delphi classes exposed to Python as binary extensions, and Python interpreter inside Delphi). I also saw a patch for Lazarus compatibility on the Google Code "issues" page, but it seems there might be some unresolved issues there.
I think there's no problem combining .EXE packaging with a tool like PyInstaller or py2exe and Python-written plugins. The created .EXE can easily detect where it's installed and the code inside can then simply import files from some pre-determined plugin directory. Don't forget that once you package a Python script into an executable, it also packages the Python interpreter inside, so there you have it - a full Python environment customized with your own code.

Categories

Resources