jcaiuwyo / cantera

Automatically exported from code.google.com/p/cantera
0 stars 0 forks source link

Failed to import cantera (python), Error using ctmethods, exit code 7 (Matlab) #211

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Importing cantera on command line in powershell or
2. running any Solution procedure (any cti file) in Matlab's command line or
3. Typing GRI30 into Matlab's command line

What is the expected output? What do you see instead?
The output is a plot of the temperature and species composition for a premixed 
flame, the basic result of any test. Instead I notice an error.

What version of the product are you using? On what operating system?
I am running Cantera 2.1.1 the most recent version, on my windows 8.1 64 bit 
system. I installed it together with the MSI file for python 3.3 
(Cantera-Python-2.1.1-x64-py3.3.msi and Cantera-2.1.1-x64.msi). I am currently 
running Python 3.3 as well. I also have installed Numpy (compatible with Python 
3.3) I have Boost (downloaded), Cython (installed), the state toolbox for 
matlab(in the python site-packages directory) ... as well as a host of other 
programs supposed to work in tandem with Cantera or python

Please provide any additional information below.
The error I receive from the powershell command line (python is running) is 
>>> import cantera
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python33\lib\site-packages\cantera\__init__.py", line 1, in <module>
    from ._cantera import *
  File "__init__.pxd", line 155, in init cantera._cantera (cantera/_cantera.cpp:69759)
  File "C:\Python33\lib\site-packages\numpy\__init__.py", line 168, in <module>
    from . import add_newdocs
  File "C:\Python33\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python33\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "C:\Python33\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\Python33\lib\site-packages\numpy\core\__init__.py", line 6, in <module>
    from . import multiarray
ImportError: DLL load failed: %1 is not a valid Win32 application.

The files referenced are from the site-packages folder in the python Lib 
folder, as installed from the state toolbox.

The error I get from typing importPhase('gri30.cti', 'gri30') (or just GRI30) 
into matlab's command line is

Error using ctmethods

************************************************
                Cantera Error!
************************************************

Procedure: ct2ctml
Error:   Error converting input file "C:/Program Files/Cantera/data/gri30.cti" 
to CTML.
Python command was: 'C:\Python33\python.exe'
The exit code was: 7
-------------- start of converter log --------------
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "C:\Python33\lib\site-packages\cantera\__init__.py", line 1, in <module>
    from ._cantera import *
  File "__init__.pxd", line 155, in init cantera._cantera (cantera/_cantera.cpp:69759)
  File "C:\Python33\lib\site-packages\numpy\__init__.py", line 168, in <module>
    from . import add_newdocs
  File "C:\Python33\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python33\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "C:\Python33\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\Python33\lib\site-packages\numpy\core\__init__.py", line 6, in <module>
    from . import multiarray
ImportError: DLL load failed: %1 is not a valid Win32 application.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
ImportError: No module named 'ctml_writer'
--------------- end of converter log ---------------

Error in XML_Node (line 11)
    x.id = ctmethods(10,15,0,src); % newxml(name)

Error in Solution (line 30)
doc = XML_Node('doc',src);

Error in GRI30 (line 22)
    s = Solution('gri30.cti','gri30');

I have also tried using other cti files with very similar results apart from 
the name of the file.

if I type  Solution('nasa_gas.cti')

I get the same error without the last two lines

Error in IdealGasMix (line 39)
            s = Solution(a);

I was getting another error (which I can add here) when I did not add the state 
toolbox, but I thought to troubleshoot it and got stuck here. I have also 
looked at past errors with the ct2ctml issue, and they do not seem to have 
helped.

 I changed the path environment variable to my python path. I am sure python is installed, as well as the cantera program.
I am yet to receive any results at all so it's telling me my problem may be 
more than just typographical.

Please help.
Tobi

Original issue reported on code.google.com by t.air4u...@gmail.com on 9 Mar 2014 at 2:20

GoogleCodeExporter commented 9 years ago
Based on these lines:

File "C:\Python33\lib\site-packages\numpy\core\__init__.py", line 6, in <module>
    from . import multiarray
ImportError: DLL load failed: %1 is not a valid Win32 application.

it seems to be a problem loading Numpy. According to this post on StackOverflow:
http://stackoverflow.com/questions/11404269/numpy-importerror-in-python-dll-load
-failed

the problem may be that your Numpy is 32-bit, while the rest of the software is 
64-bit. Can you check that?

Bryan

Original comment by bryan.w....@gmail.com on 10 Mar 2014 at 1:41

GoogleCodeExporter commented 9 years ago
You can get a binary installer version of Numpy from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

Original comment by bryan.w....@gmail.com on 10 Mar 2014 at 1:42

GoogleCodeExporter commented 9 years ago
Tobi,

How did you install Numpy, and what version do you have? What is the result of 
running the following commands in Python?

    >>> import sys; print(sys.version)
    >>> import numpy
    >>> print(numpy.__version__)

If you get an error on importing Numpy, try the installer from the site Bryan 
linked to.

Original comment by yarmond on 11 Mar 2014 at 2:16

GoogleCodeExporter commented 9 years ago
Thanks Bryan and Yarmond.
I reinstalled Numpy. I am currently able to run the program from matlab as an 
admin.
Running from matlab without the administrator priviledges results in this error 
when I enter Solution('nasa_gas.cti') into the command line
Error using ctmethods

************************************************
                Cantera Error!
************************************************

Procedure: ct2ctml
Error:   Error converting input file "C:/Users/air/Documents/data/nasa_gas.cti" 
to CTML.
Python command was: 'C:\Python33\python.exe'
The exit code was: 7
-------------- start of converter log --------------
Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
  File "C:\Python33\Lib\site-packages\cantera\ctml_writer.py", line 2597, in convert
    write(outName)
  File "C:\Python33\Lib\site-packages\cantera\ctml_writer.py", line 338, in write
    x.write(_name+'.xml')
  File "C:\Python33\Lib\site-packages\cantera\ctml_writer.py", line 133, in write
    with open(filename, 'w') as f:
PermissionError: [Errno 13] Permission denied: 'nasa_gas.xml'
--------------- end of converter log ---------------

Error in XML_Node (line 11)
    x.id = ctmethods(10,15,0,src); % newxml(name)

Error in Solution (line 30)
doc = XML_Node('doc',src);

I can now import numpy and cantera from python
however I get this error if I run cantera.Solution('nasa_gas.cti')

>>> import cantera
>>> cantera.Solution('nasa_gas.cti')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "base.pyx", line 30, in cantera._cantera._SolutionBase.__cinit__ (cantera/_cantera.cpp:5652)
ValueError: Couldn't read phase node from XML file

If I run python as an admin, I get the following error running the same code in 
powershell

Python 3.3.4 (v3.3.4:7ff62415e426, Feb 10 2014, 18:13:51) [MSC v.1600 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cantera
>>> cantera.Solution('nasa_gas.cti')
get_CTML_Tree: caught an exception:

***********************************************************************
CanteraError thrown by ct2ctml:
Error converting input file "C:\Users\air\Documents\data/nasa_gas.cti" to CTML.
Python command was: 'C:\Python33\python.exe'
The exit code was: 7
-------------- start of converter log --------------
Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
  File "C:\Python33\Lib\site-packages\cantera\ctml_writer.py", line 2597, in con
vert
    write(outName)
  File "C:\Python33\Lib\site-packages\cantera\ctml_writer.py", line 338, in writ
e
    x.write(_name+'.xml')
  File "C:\Python33\Lib\site-packages\cantera\ctml_writer.py", line 133, in writ
e
    with open(filename, 'w') as f:
PermissionError: [Errno 13] Permission denied: 'nasa_gas.xml'
--------------- end of converter log ---------------
***********************************************************************
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "base.pyx", line 21, in cantera._cantera._SolutionBase.__cinit__ (cantera
/_cantera.cpp:5594)
RuntimeError:
***********************************************************************
CanteraError thrown by get_CTML_Tree:
XML file ./nasa_gas.xml not found
***********************************************************************

Indicating an issue with file permissions, similar to running matlab without 
admin priviledges. I'm looking through similar posts for solutions.

Original comment by t.air4u...@gmail.com on 12 Mar 2014 at 5:25

GoogleCodeExporter commented 9 years ago
The following error when trying to import nasa_gas.cti is expected in all cases:

    ValueError: Couldn't read phase node from XML file

because that file only contains species definitions to be used by other input 
files. I'm not sure where the idea that importing nasa_gas.cti directly should 
work comes from. If you import an input file with a phase definition, e.g. 
h2o2.cti, you should not get this error.

The permissions errors are exactly what they say they are: You need write 
access to the current working directory so that Cantera can save the converted 
.cti file. This is not a problem with Cantera.

Original comment by yarmond on 13 Mar 2014 at 12:55

GoogleCodeExporter commented 9 years ago

Original comment by yarmond on 13 Mar 2014 at 12:56

GoogleCodeExporter commented 9 years ago
I have a similar error appearing. This is Cantera 2.1.x, and the setup_cantera 
calls python2.7. Numpy is happily installed, version 1.9.0. 
Running from matlab I get : 

>>gas1=GRI30

Procedure: ct2ctml
Error:   Error converting input file 
"/usr/local/Cellar/cantera/2.1.x/share/cantera/data/gri30.cti" to
CTML.
Python command was: '/usr/local/bin/python'
The exit code was: 7
-------------- start of converter log --------------
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
ImportError: No module named ctml_writer
--------------- end of converter log ---------------

Running from python works fine. 

Ideas? 

Original comment by Simone.H...@gmail.com on 14 Oct 2014 at 4:14