Paraview: paraview.simple import, all paths are set - python

I am trying to run a simple python program, importing the paraview.simple module:
from paraview.simple import *
I get the following error:
Error: Could not import vtkCommonComputationalGeometry
I looked at similar posts on different fora and tried everything that was suggested there, but nothing worked for me. My Python path includes:
ParaView-5.7.0-MPI-Linux-Python2.7-64bit/bin/
ParaView-5.7.0-MPI-Linux-Python2.7-64bit/lib
ParaView-5.7.0-MPI-Linux-Python2.7-64bit/lib/python2.7/site-packages/
My LD_LIBRARY_PATH includes:
ParaView-5.7.0-MPI-Linux-Python2.7-64bit/lib/python2.7/site-packages/vtkmodules/
Does anybody know how to fix it?
Update:
I think there is an underline issue regarding the Unicode variant my python interpreter is using. I now get the following error:
Unicode error
ImportError: /home/nick/ParaView-5.7.0-MPI-Linux-Python2.7-64bit/lib/python2.7/site-packages/vtkmodules/vtkCommonCorePython.so: undefined symbol: PyUnicodeUCS2_DecodeUTF8
Does anybody know a fix?

You may want to use the pvpython program that is bundled with ParaView. It is basically a python interpreter but already setup with the correct paths.
If you want to use an external interpreter, you have to setup the PYTHONPATH environment variable to ParaView-5.7.0-MPI-Linux-Python2.7-64bit/lib/python2.7/site-packages/ and the LD_LIBRARY_PATH (on linux, PATH on windows) to ParaView-5.7.0-MPI-Linux-Python2.7-64bit/lib.
See also the ParaViewTutorial pdf from the download page (https://www.paraview.org/download/), at 3.1 Starting the Python Interpreter

Related

Python gives error when importing simple C extension module

On windows I have built a very simple "hello world" C extension (the file hello.c from this site https://gist.github.com/physacco/2e1b52415f3a964ad2a542a99bebed8f). Using VS2015 I successfully obtain hello.dll. The problem is that I can't figure out how to import this file/module.
In the python shell (python 3.7) I have made sure that I'm in the same folder as the hello.dll. I have also made sure that sys.path() contains the folder path. But when I write "import hello" I get an error "ModuleNotFoundError: No module named 'hello'"
Does anyone has an idea of what is wrong is this very simple setup?
Update:
When trying to import a module that does not exist the ModuleNotFoundError is reported. After renaming the hello.dll to hello.pyd an ImportError is returned. So it seems like it tries to actually load the module.
Python compiled modules on Windows have the extension .pyd, not .dll. If you'd built it using setup.py the file would be built with the correct name. However, you built it yourself and gave it a name that Python doesn't recognise as a module.
In terms of the build command: you have to link it with libpython. You don't look to be doing this. The error you report is definitely one that you can get if the module is not linked against all its dependencies.
I know you don't want to use setup.py, however I'd use it at least once just to see what it does and if it works. You'll then at least have a command that you can copy with a working set of options.

Embedded python not picking up PYTHONPATH

I have a really weird problem with embedding python. If I don't specify PYTHONPATH, Py_Initialize fails with ImportError: No module named site.
If I set PYTHONPATH in cmd and then run my program, it works!
If I set PYTHONPATH programmatically (_putenv_s / SetEnvironmentVariable) it fails with ImportError again.
I've checked that the value is set with system("echo %PYTHONPATH%");, I've made sure multiple times that it is the correct path. I have no idea why it's failing... any ideas appreciated.
Setup: win10 x64, stackless python 2.7 x86 embedded in a C program.
https://bugs.python.org/issue28245
I found that python37._pth could be used to configure the sys.path info.
python37.zip
.
Lib
Lib\site-packages
# Uncomment to run site.main() automatically
#import site
Turns out I had to set PYTHONPATH before, then load the dll with a delay. The python library I have seems to be non-standard / modified.

Problems importing a python module in Maya and it being recognized

Still learning certain things about Python... I am having issues recognizing my Python script in my scripts dir. First, I checked to see that my path is set correctly:
import sys
for pythonPath in sys.path:
print pythonPath
And C:/Users/..../Documents/maya/2014-x64/scripts is listed, which is where I am placing swap.py
In Maya's script editor I am typing the following:
import swap
reload(swap)
swap.printSomething()
I get:
Error: AttributeError: file line 3: 'module' object has no attribute 'printSomething' #
If I take the same code and throw it into a package...
C:/Users/..../Documents/maya/2014-x64/scripts/swapPackage/swap.py
And then call this, it works...
import swapPackage.swap as swap
reload(swap)
swap.printSomething()
Why? I am totally confused. Mel scripts even run fine from this location as well. I just can't get a simple python script to import and run.
Also something I noticed. Even though I can get this script to run in a package, the package name must be totally different than the module name. I can't have a package named this:
C:/Users/..../Documents/maya/2014-x64/scripts/swap/swap.py
but I can have one where the package name is different:
C:/Users/..../Documents/maya/2014-x64/scripts/swapPackage/swap.py
Ok folks, I was able to solve this by executing a print of my file, only to find out that it was sourcing a totally different version someone copied elsewhere. ARGH. This solves both issues, and makes sense why changing the package name from the module worked.
import swap
reload(swap)
print swap.__file__

Python 3.3.5 time module missing

When I try to import time I get : No module named time
I have tried other time modules(datetime and timeit) and they work fine. I decided to check my installation and I can't find time.py anywhere. I checked the Lib, Scripts, libs and include folders, but can't find it anywhere.
Anyone know what I can do to fix this? Maybe download the .py and put it in Lib myself?
I am using Python 3.3.5 with PyCharm IDE. Only extra scripts I've installed is EasyInstall and PRAW.
The import does work. When PyCharm said No module named time, I assumed I would get a compiler error and started trying to fix it.
However when I eventually just ran the code it worked fine. I expect PyCharm doesn't detect the time module as it's a dll and not a py as noted by Martijn in the comments. This is on PyCharm Community Edition 4.0.4.
I tried playing with virtualenv and a host of other things, but I eventually went to Preferences -> Build, Execution, Deployment -> Console -> Python Console, and in the "starting script" box, I added two lines:
sys.builtin_module_names.append('sys')
sys.builtin_module_names.append('time')
This got rid of errors I had with both sys and time. Once I did that, I even get autocomplete for both of those modules... weird.

issue with vtk python wrapping: can't import vtk in interpreter but can import in console

I compiled vtk with python wrapping and I can us it on the command line.
However, I am using eclipse IDE and want to use vtk but no matter what I do with my PYTHONPATH variable, I still get the errors below:
from filtering import *
File "C:\Development\third-party\vtk-5.6.1\build\Wrapping\Python\vtk\filtering.py", line 9, in <module>
from vtkFilteringPython import *
ImportError: DLL load failed: The specified procedure could not be found.
My PATH and PYTHONPATH contain:
"C:\Development\third-party\vtk-5.6.1\Wrapping\Python"
"C:\Development\third-party\vtk-5.6.1\build\bin\Release" which has the *.lib, *.pyd, *.dll
In the DOS console, that is all I need and I can "import vtk" with no errors.
However, in eclipse I set the "External Libraries" of my project to contain the same directories above and I get an error.
The error happens at in the file "C:\Development\third-party\vtk-5.6.1\Wrapping\Python\vtk__init__.py" :
just after loading vtk "common" library.
...
# Load all required kits.
from common import *
from filtering import *
...
The funny thing is that both vtkcommon and vtkfiltering python (.dll, .lib and .pyd) are all in the same folder here: "C:\Development\third-party\vtk-5.6.1\build\bin\Release"
Can someone please help ? Why would import vtk work on console and not in eclipse IDE ?
I am using Version: Juno Service Release 2
Build id: 20130225-0426 for eclipse, vtk-5.6, python 2.6.5 and pydev 2.7.3
Can anyone with pydev + vtk experience help me?
I was having problems with VTK on PyDev and I just found this article, to do with PyCUDA on PyDev. It helped me get things working on Linux.
I followed the instructions there: Go to Run->Run Configurations and add a new environment variable LD_LIBRARY_PATH
I also found this forum, which deals with a similar problem on Windows. They suggest adding
-Djava.library.path="{dll path}"
to your runtime args in eclipse. See this page on the eclipse wiki.

Categories