Jacques Basaldúa
Jacques Basaldúa

Reputation: 31

Cannot build cython code from a conda environment

I am using anaconda in windows. My root environment has python 2.7 and an alternative environment named py34 has python 3.4. I am new to cython, trying it out for a project needing linking with C. I can successfully build and run cython examples in the root environment, but fail to build the same examples with py34.

When I do that from the root environment it works fine:

C:\ETC\py34>python setup.py build_ext --inplace
Compiling hello.pyx because it changed.
Cythonizing hello.pyx
running build_ext
building 'hello' extension
c:\Anaconda\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -Ic:\Anaconda\include -Ic:\Anaconda\PC -c hello.c -o build\temp.wi
n-amd64-2.7\Release\hello.o
writing build\temp.win-amd64-2.7\Release\hello.def
c:\Anaconda\Scripts\gcc.bat -DMS_WIN64 -shared -s build\temp.win-amd64-2.7\Release\hello.o build\temp.win-amd64-2.7\Rele
ase\hello.def -Lc:\Anaconda\libs -Lc:\Anaconda\PCbuild\amd64 -lpython27 -lmsvcr90 -o C:\ETC\py34\hello.pyd

But from a python 3.4 environment it fails:

[py34] C:\ETC\py34>python setup.py build_ext --inplace
running build_ext
error: [WinError 2] El sistema no puede encontrar el archivo especificado

It looks like the "activate py34" is unable to set all the paths correctly for cython to work.

Please, help.

Update: The problem seems to be related with python 3.4, not the fact that it is a conda environment. I created a new py33 environment with python 3.3 and it works fine. For me this solution is good enough, I want my project to support python 3.xx. Support for 3.4 can wait. Probably, there is ongoing work to fix cython support for python 3.4.

Upvotes: 3

Views: 2142

Answers (1)

P.R.
P.R.

Reputation: 3927

This is an old question, but I had a similar problem just yesterday. My solution was to build a switch into the setup.py, which adds the LIBRARY_INC and LIBRARY_LIB path to the include_dirs and library_dirs of the distutils.

import platform
from distutils.core import setup, Extension

if platform.system() == 'Windows':
    try:
        include_dirs = [os.environ['LIBRARY_INC']]
    except KeyError:
        include_dirs = []
    try:
        library_dirs = [os.environ['LIBRARY_LIB']]
    except KeyError:
        library_dirs = []

...
setup(ext_modules=[
        Extension(...
                include_dirs=include_dirs,
                libraries=...,
                library_dirs=library_dirs)

Upvotes: 1

Related Questions