Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation Question #32

Closed
sandeepjella opened this issue May 25, 2018 · 6 comments
Closed

Installation Question #32

sandeepjella opened this issue May 25, 2018 · 6 comments

Comments

@sandeepjella
Copy link

I'm using Cantera + Python in Anaconda and have installed pyjac. Works well and generates the C code but I am running into an issue trying to generate the C wrapper that works on that output for later use in Python (i.e. a cantera program).

It is fairly silly: Pyjac doesn't find the gcc compiler, which is installed through MingW in the Anaconda environment. Outside Pyjac's run, the conda prompt is able to find gcc.

I don't think this is a PyJac issue but perhaps someone could spot the obvious and put me out of my misery?

Best wishes,

Sandeep

@skyreflectedinmirrors
Copy link
Collaborator

skyreflectedinmirrors commented May 25, 2018

Hi Sandeep,

Just so I'm clear here, the steps involved in this issue are:

  1. Install pyJac on windows
  2. Generate the c-code
  3. use pyjac.pywrap to generate a python wrapper for the generated C-code

Is that right?

If so, I think the issue is with paths / Conda. I don't know that anyone's ever tested pyJac with MinGW, but this is something we should support.

First things to check:

  1. Can you call gcc via the Anaconda prompt (that you run python from)?

For example, on my MinGW installed Conda env, the command gcc -v yields:

gcc -v
Using built-in specs.
COLLECT_GCC=C:\ProgramData\Miniconda3\Scripts\gcc.bat\..\..\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/programdata/miniconda3/mingw/bin/../libexec/gcc/x86_64-w64-mingw32/4.7.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../build/gcc/src/configure --target=x86_64-w64-mingw32 --prefix=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root --with-sysroot=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root --enable-languages=all,obj-c++ --enable-fully-dynamic-string --disable-multilib
Thread model: win32
gcc version 4.7.0 20111220 (experimental) (GCC)
  1. However, when I call gcc within python:
python
>>> import subprocess
>>> subprocess.call(['gcc', '-v'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Miniconda3\lib\subprocess.py", line 267, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\ProgramData\Miniconda3\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\ProgramData\Miniconda3\lib\subprocess.py", line 992, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

I think the issue here is that subprocess doesn't inherit the conda path when looking for gcc (but it would, once it actually launches gcc).

For instance,

subprocess.call(['gcc', '-v'], env=os.environ, shell=True)

yields:

COLLECT_GCC=C:\ProgramData\Miniconda3\Scripts\gcc.bat\..\..\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/programdata/miniconda3/mingw/bin/../libexec/gcc/x86_64-w64-mingw32/4.7.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../build/gcc/src/configure --target=x86_64-w64-mingw32 --prefix=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root --with-sysroot=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root --enable-languages=all,obj-c++ --enable-fully-dynamic-string --disable-multilib
Thread model: win32
gcc version 4.7.0 20111220 (experimental) (GCC)

So the quick fix is to put shell=True in the subprocess call on lines 111 & 207 in libgen.py.
In order to do so, you should uninstall pyJac via conda, clone this repo, make these changes and then install your modified version of pyJac via pip

I'll investigate a longer-term fix

@sandeepjella
Copy link
Author

sandeepjella commented May 25, 2018 via email

@skyreflectedinmirrors
Copy link
Collaborator

Sandeep, I'm still running into some issues getting the python wrapper to fully compile here on windows (you have to do similar things to the linker and there's some Cython weirdness), but I should have a pull request for you to test later this afternoon

@sandeepjella
Copy link
Author

sandeepjella commented May 25, 2018 via email

@skyreflectedinmirrors
Copy link
Collaborator

skyreflectedinmirrors commented May 25, 2018

Ok, so this is actually a bit more complicated than I hoped.
Unfortunately Conda compiles everything with MSVC compilers on windows, and there are some serious incompatibilities between the MinGW and MSVC python run-time libraries.

The mingwpy project was started to try and get around this type of thing, but has since been abandoned.

I could get the C-library to compile, but linking it into a python module for import is proving difficult. So we have some options here:

  1. Implement a MSVC C target -- a bit annoying since it'll require you either have MSVC installed (or the Microsoft SDK's)

  2. Go to linux where life becomes much less of an issue!

I've also added a mingw branch you could try out.

For me, this fails with:

python -m pyjac.pywrap -l c -so out
...
subprocess.CalledProcessError: Command '['C:\\ProgramData\\Miniconda3\\python.exe', 'C:\\ProgramData\\Miniconda3\\lib\\site-packages\\pyjac\\pywrap\\pyjacob_setup.py', 'build_ext', '--build-lib', 'C:\\Users\\njc07003\\Desktop\\test', '--compiler=mingw32']' returned non-zero exit status 1.

which if you run directly, yields:

C:\ProgramData\Miniconda3\python.exe C:\ProgramData\Miniconda3\lib\site-packages\pyjac\pywrap\pyjacob_setup.py build_ext --build-lib C:\Users\njc07003\Desktop\test --compiler=mingw32
...
writing c:\programdata\miniconda3\lib\site-packages\pyjac\pywrap\pyjacob.cp36-win_amd64.def
C:\ProgramData\Miniconda3\pkgs\mingw-4.7-1\MinGW\bin\gcc.exe -shared -s c:\programdata\miniconda3\lib\site-packages\pyjac\pywrap\pyjacob_wrapper.o C:\Users\njc07003\Desktop\test\build\temp.win-amd64-3.6\libc_pyjac.a c:\programdata\miniconda3\lib\site-packages\pyjac\pywrap\pyjacob.cp36-win_amd64.def -LC:\ProgramData\Miniconda3\libs -LC:\ProgramData\Miniconda3\PCbuild\amd64 -lpython36 -lmsvcr140 -o C:\Users\njc07003\Desktop\test\pyjacob.cp36-win_amd64.pyd
c:/programdata/miniconda3/pkgs/mingw-4.7-1/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:\programdata\miniconda3\lib\site-packages\pyjac\pywrap\pyjacob.cp36-win_amd64.def:1: syntax error
c:/programdata/miniconda3/pkgs/mingw-4.7-1/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld.exe:c:\programdata\miniconda3\lib\site-packages\pyjac\pywrap\pyjacob.cp36-win_amd64.def: file format not recognized; treating as linker script
c:/programdata/miniconda3/pkgs/mingw-4.7-1/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld.exe:c:\programdata\miniconda3\lib\site-packages\pyjac\pywrap\pyjacob.cp36-win_amd64.def:1: syntax error
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\ProgramData\\Miniconda3\\pkgs\\mingw-4.7-1\\MinGW\\bin\\gcc.exe' failed with exit status 1

Pretty sure those "file format not recognized; treating as a linker script" is the root of the error here, but I can't find much info about it

@sandeepjella
Copy link
Author

sandeepjella commented May 26, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants