|
[Sponsors] |
December 29, 2015, 07:15 |
import function from file
|
#1 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
Hi,
I just installed open foam 3.0 with paraview 4.4 from the source codes on the git repository, and everything is working fine, except that when I try to import a function from a file which is located in the CWD (for example sigan) Code:
ImportError: No module named sigan The same problem is not present in my parafoam 4.1 install on another computer (also on linux mint, 17.2), has anyone else had this problem with this on 4.4? |
|
December 29, 2015, 08:32 |
|
#2 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
Greetings Sean,
This is essentially a Python question The real problem is whether you are trying to import a function or if you are trying to run a script, because the two have different ways of being done. Loading a Python script as a module requires the folder to be in Python's search path, as defined by the environment variable... er... gotta got look it up... oh, nice, I've written about this in the past: http://www.cfd-online.com/Forums/ope...tml#post571136 post #7 - therefore, you will have to add the current path to the environment variable "PYTHONPATH". On the other hand, running a Python script from Python... here you go: https://docs.python.org/2/library/fu....html#execfile So it should be something like this: Code:
execfile("/full/path/to/script/test.py") Bruno
__________________
|
|
December 29, 2015, 18:54 |
|
#3 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
Thanks Bruno,
I had a similar problem a few months back, and seem to remember I got it working, you can see the post here: http://www.cfd-online.com/Forums/par...-pvpython.html The strange thing is that now the same problem is recurring if I try on the original system (linux mint 17.2 with paraview 4.1, as in the above post) I know for example that if I open python directly (as opposed to pvpython) in the same directory that the same syntax works fine (eg from sigan import *). I don't remember having to change anything in the python path last time, not sure what I'm doing wrong now... |
|
December 30, 2015, 07:10 |
|
#4 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
Hi Sean,
ParaView's Python environment is created in a separate environment, which is why the current from where you started ParaView does not match with the one inside the Python environment within ParaView. I need detailed steps in order to try and replicate the same scenario you are working with. Knowing what the following commands give you in the command line can help: Code:
echo $PYTHONPATH echo $PV_PLUGIN_PATH Best regards, Bruno |
|
December 30, 2015, 19:47 |
|
#5 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
Thanks Bruno,
The Python path is /lib/paraview-4.4/site-packages:/lib/paraview-4.4/site-packages/vtk the PV_PLUGIN_PATH is /home/sean/OpenFOAM/OpenFOAM-4.0.x/platforms/linux64GccDPInt32Opt/lib/paraview-4.4 I'm starting paraview from the terminal, interestingly os.getcwd() is returning the directory from which I started paraview |
|
December 31, 2015, 08:04 |
|
#7 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
which paraview returns
/home/sean/OpenFOAM/ThirdParty-3.0.x/platforms/linux64Gcc/ParaView-4.4.0/bin/paraview I still haven't set up the python path properly on this install, so the python path is just what is in my old .bashrc (which got copied over in my dejadup backup). PYTHONPATH was defined before the line pointing to $HOME/OpenFOAM/OpenFOAM-3.0.x/etc/bashrc so it was showing strangely. After fixing this the PYTHONPATH is: /home/sean/OpenFOAM/ThirdParty-3.0.x/platforms/linux64Gcc/ParaView-4.4.0/lib/paraview-4.4/site-packages:/home/sean/OpenFOAM/ThirdParty-3.0.x/platforms/linux64Gcc/ParaView-4.4.0/lib/paraview-4.4/site-packages/vtk I installed paraview 4.4 by compiling from the git repository source code (linux mint won't take the debian packages) but was having the same problem on ubuntu 15.10 installed from the debian packages through apt-get |
|
December 31, 2015, 21:55 |
|
#9 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
No, still the same for sigan or any *.py file
|
|
January 1, 2016, 10:59 |
|
#10 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
Quick answer: "testingMyStuff.py" is my test script:
Code:
import os, sys sys.path.append(os.getcwd()) import testingMyStuff |
|
January 2, 2016, 01:38 |
|
#11 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
Thanks that worked fine, still not sure why this problem arose in the first place...
|
|
January 11, 2016, 01:33 |
|
#12 |
Member
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 12 |
Now a quick follow up question, is there a way to add
Code:
import os, sys sys.path.append(os.getcwd()) import testingMyStuff |
|
January 31, 2016, 12:59 |
|
#13 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
Quick answer (although 20 days after your question): It's explained here: http://stackoverflow.com/questions/1...on-interpreter
|
|
Tags |
paraview 4.4.0, python |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 13:41 |
[blockMesh] error message with modeling a cube with a hold at the center | hsingtzu | OpenFOAM Meshing & Mesh Conversion | 2 | March 14, 2012 10:56 |
OpenFOAM on MinGW crosscompiler hosted on Linux | allenzhao | OpenFOAM Installation | 127 | January 30, 2009 20:08 |
DecomposePar links against liblamso0 with OpenMPI | jens_klostermann | OpenFOAM Bugs | 11 | June 28, 2007 18:51 |
[blockMesh] Axisymmetrical mesh | Rasmus Gjesing (Gjesing) | OpenFOAM Meshing & Mesh Conversion | 10 | April 2, 2007 15:00 |