CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[PyFoam] library import error

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 14, 2014, 11:41
Default library import error
  #1
New Member
 
Join Date: Jan 2014
Posts: 4
Rep Power: 12
00Sibbe is on a distinguished road
Hi,

I am new to this forum and also quite new to using OpenFOAM in general and PyFoam in special. PyFoam is a powerful tool and I am glad to be able to take advantage of its additional capabilities. However, when writing my own PyFoam I keep getting the following error:

Traceback (most recent call last):
File "readbb.py", line 2, in <module>
from PyFoam.Execution.BasicRunner import BasicRunner
File "/usr/lib/python2.6/site-packages/PyFoam/Execution/BasicRunner.py", line 14, in <module>
from PyFoam.Basics.DataStructures import makePrimitiveString
File "/usr/lib/python2.6/site-packages/PyFoam/Basics/DataStructures.py", line 5, in <module>
import PyFoam.Basics.FoamFileGenerator
File "/usr/lib/python2.6/site-packages/PyFoam/Basics/FoamFileGenerator.py", line 5, in <module>
from PyFoam.Basics.DataStructures import Vector,Field,Dimension,TupleProxy,DictProxy,Tensor ,SymmTensor,Unparsed,UnparsedList,Codestream,DictR edirection,BinaryList,BoolProxy
ImportError: cannot import name Vector


when I try to import PyFoam libraries at the beginning of a python script, e.g. by:

import os, shutil
from PyFoam.Execution.BasicRunner import BasicRunner

I have python version 2.6.6 installed on a CentOS 6.5 machine, I am using OpenFOAM 2.3.0 and PyFoam 0.6.3 version (installation as root).
I already checked some things recommended at the openfoam wiki homepage .

Can anybody help me to fix this error?
Any help is very appreciated, thank you in advance.

Regards,
Sebastian
00Sibbe is offline   Reply With Quote

Old   October 15, 2014, 07:13
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by 00Sibbe View Post
Hi,

I am new to this forum and also quite new to using OpenFOAM in general and PyFoam in special. PyFoam is a powerful tool and I am glad to be able to take advantage of its additional capabilities. However, when writing my own PyFoam I keep getting the following error:

Traceback (most recent call last):
File "readbb.py", line 2, in <module>
from PyFoam.Execution.BasicRunner import BasicRunner
File "/usr/lib/python2.6/site-packages/PyFoam/Execution/BasicRunner.py", line 14, in <module>
from PyFoam.Basics.DataStructures import makePrimitiveString
File "/usr/lib/python2.6/site-packages/PyFoam/Basics/DataStructures.py", line 5, in <module>
import PyFoam.Basics.FoamFileGenerator
File "/usr/lib/python2.6/site-packages/PyFoam/Basics/FoamFileGenerator.py", line 5, in <module>
from PyFoam.Basics.DataStructures import Vector,Field,Dimension,TupleProxy,DictProxy,Tensor ,SymmTensor,Unparsed,UnparsedList,Codestream,DictR edirection,BinaryList,BoolProxy
ImportError: cannot import name Vector


when I try to import PyFoam libraries at the beginning of a python script, e.g. by:

import os, shutil
from PyFoam.Execution.BasicRunner import BasicRunner

I have python version 2.6.6 installed on a CentOS 6.5 machine, I am using OpenFOAM 2.3.0 and PyFoam 0.6.3 version (installation as root).
I already checked some things recommended at the openfoam wiki homepage .

Can anybody help me to fix this error?
Any help is very appreciated, thank you in advance.

Regards,
Sebastian
That is strange. Tried it on two different machines and no problem. And it would break a lot of stuff if there was a problem. Basically what it says is "in DataStructures.py" there is no 'thing' called Vector". Check your file /usr/lib/python2.6/site-packages/PyFoam/Basics/DataStructures.py. There should be a class Vector somewhere. That class has been around for a long time so I don't think it is a "it works for Bernhard because he's got the development version"-issue. Check whether the DataStructures.py you have is the same as in the downloaded tar of PyFoam
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   October 15, 2014, 08:57
Default
  #3
New Member
 
Join Date: Jan 2014
Posts: 4
Rep Power: 12
00Sibbe is on a distinguished road
Thank you for your feedback, Bernhard.
I have checked the /usr/lib/python2.6/site-packages/PyFoam/Basics/DataStructures.py file as you mentioned and I found the vector structure inside it:

class Vector(FixedLength):
def __init___(self,x,y,z):
FixedLength.__init__(self,[x,y,z])
(...)

It is the same definition as in the downloaded tar. I also did a reinstallation and I am sure not to have manipulated it by myself.

Maybe it is worth mentioning that single PyFoam applications (e.g. pyFoamPlotRunner.py) work as well as does a script that includes libraries from the 'applications' folder of PyFoam.

Best,
Sebastian
00Sibbe is offline   Reply With Quote

Old   October 15, 2014, 09:58
Default
  #4
New Member
 
Join Date: Jan 2014
Posts: 4
Rep Power: 12
00Sibbe is on a distinguished road
I just found out that everything works out fine on my working machine if I download and install PyFoam version 0.6.2 instead.
So from what I've found out so far, the problem seems to have something to do with pyfoam version 0.6.3. But I still don't get why.

Regards,
Sebastian
00Sibbe is offline   Reply With Quote

Old   October 15, 2014, 12:07
Default
  #5
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by 00Sibbe View Post
I just found out that everything works out fine on my working machine if I download and install PyFoam version 0.6.2 instead.
So from what I've found out so far, the problem seems to have something to do with pyfoam version 0.6.3. But I still don't get why.

Regards,
Sebastian
I can't reproduce your problem with the import you give but with
Code:
from PyFoam.Basics import DataStructures
this seems to be a circular-dependency problem. I can work around it with
Code:
from PyFoam.Basics import FoamFileGenerator
from PyFoam.Basics import DataStructures
So importing FoamFileGenerator first seems to fix this. I'll have a look how to fix this permanently

Added a ticket on Sourceforge: https://sourceforge.net/p/openfoam-e...etspyfoam/219/
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request

Last edited by gschaider; October 15, 2014 at 12:18. Reason: Ticket added
gschaider is offline   Reply With Quote

Old   October 15, 2014, 12:41
Default
  #6
New Member
 
Join Date: Jan 2014
Posts: 4
Rep Power: 12
00Sibbe is on a distinguished road
Thanks a lot for this information. It helped and solved the problem! If I start my script with

import os, shutil
from PyFoam.Basics import FoamFileGenerator
from PyFoam.Execution.BasicRunner import BasicRunner

the error message stated above doesn't appear anymore and it also works for PyFoam version 0.6.3. So in fact, it seems to have been a circular-dependency problem.

Anyway starting the python script with

import os, shutil
from PyFoam.Execution.BasicRunner import BasicRunner

didn't give any errors in PyFoam 0.6.2 version. This is what I was trying to express with my last post. So my guess is that inter-dependencies of different pyfoam classes might have changed for the new version

So thank you again,
regards
00Sibbe is offline   Reply With Quote

Reply


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
Could not import tets Aeronautics El. K. Pointwise & Gridgen 6 April 27, 2023 03:38
[OpenFOAM.org] compile error in dynamicMesh and thermophysicalModels libraries NickG OpenFOAM Installation 3 December 30, 2019 01:21
[blockMesh] blockMesh with double grading. spwater OpenFOAM Meshing & Mesh Conversion 92 January 12, 2019 10:00
Ansys Fluent 13.0 UDF compilation problem in Window XP (32 bit) Yogini Fluent UDF and Scheme Programming 7 October 3, 2012 08:24
checking the system setup and Qt version vivek070176 OpenFOAM Installation 22 June 1, 2010 13:34


All times are GMT -4. The time now is 20:56.