CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Visualization & Post-Processing Software > ParaView

[OpenFOAM] import function from file

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By wyldckat

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 29, 2015, 06:15
Default import function from file
  #1
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
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
I'm using linux mint 17.3, but had the same problem with the debian pack install in ubuntu 15.10 (same version open foam and paraview)

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?
seanread is offline   Reply With Quote

Old   December 29, 2015, 07:32
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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")
Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   December 29, 2015, 17:54
Default
  #3
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
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...
seanread is offline   Reply With Quote

Old   December 30, 2015, 06:10
Default
  #4
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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
... as well as knowing how exactly you are launching ParaView, namely if from the command line or interactively.

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   December 30, 2015, 18:47
Default
  #5
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
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
seanread is offline   Reply With Quote

Old   December 31, 2015, 06:30
Default
  #6
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Sean,

Quote:
Originally Posted by seanread View Post
The Python path is /lib/paraview-4.4/site-packages:/lib/paraview-4.4/site-packages/vtk
That's a somewhat strange path!? How exactly did you install ParaView 4.4?

And what does this command give you?
Code:
which paraview
Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   December 31, 2015, 07:04
Default
  #7
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
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
seanread is offline   Reply With Quote

Old   December 31, 2015, 07:21
Default
  #8
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Then does it work properly with the updated PYTHONPATH? Or does it still have issues importing the "sigan" file?
wyldckat is offline   Reply With Quote

Old   December 31, 2015, 20:55
Default
  #9
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
No, still the same for sigan or any *.py file
seanread is offline   Reply With Quote

Old   January 1, 2016, 09:59
Default
  #10
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer: "testingMyStuff.py" is my test script:
Code:
import os, sys
sys.path.append(os.getcwd())
import testingMyStuff
Source: http://stackoverflow.com/a/1112661
wyldckat is offline   Reply With Quote

Old   January 2, 2016, 00:38
Default
  #11
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
Thanks that worked fine, still not sure why this problem arose in the first place...
seanread is offline   Reply With Quote

Old   January 11, 2016, 00:33
Default
  #12
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
Now a quick follow up question, is there a way to add
Code:
import os, sys
sys.path.append(os.getcwd())
import testingMyStuff
To pvpython automatically on startup so that I don't have to manually enter it every time I start paraview?
seanread is offline   Reply With Quote

Old   January 31, 2016, 11:59
Default
  #13
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer (although 20 days after your question): It's explained here: http://stackoverflow.com/questions/1...on-interpreter
seanread likes this.
wyldckat is offline   Reply With Quote

Reply

Tags
paraview 4.4.0, python


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[swak4Foam] Error bulding swak4Foam sfigato OpenFOAM Community Contributions 18 August 22, 2013 12:41
[blockMesh] error message with modeling a cube with a hold at the center hsingtzu OpenFOAM Meshing & Mesh Conversion 2 March 14, 2012 09:56
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 14:00


All times are GMT -4. The time now is 07:32.