I am following this answer from a post about compiling Cython to exe.
Here is the what python prints when I start it (for version):
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32
and for gcc --version
:
gcc (rubenvb-4.7.2-release) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
I have two files for compilation: setup.py
and hello.pyx
.
hello.pyx
:
cdef char* say_hello_to(char* name):
return "Hello %s!" % name
# I know this may not work but removing it does
# not make a difference in the error message
print say_hello_to("bob")
setup.py
:
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = 'Hello world app',
ext_modules = cythonize("hello.pyx"),
)
I ran cython hello.pyx --embed
without errors and produced a hello.c
file. Then, as I am running on Windows 10 64-bit AMD, I compiled with this (no errors raised):
gcc hello.c -I \Python27\include\ -L \Python27\libs\ -l python27 -o test.exe -D MS_WIN64
However, when I run test.exe
in my command prompt, it will show an error:
ImportError: No module named site
I googled it, and the closest question I could find was Python (Windows) - ImportError: No module named site. The answers suggested that I set
PYTHONPATH
, PYTHONHOME
and PATH
. Which I did accordingly with the following few commands:
SET PYTHONHOME=C:\Python27
SET PYTHONPATH=C:\Python27\Lib
SET PATH=%PYTHONHOME%;%PYTHONPATH%;C:\MinGW\bin\;C:\MinGW;C:\Python27\Scripts;
Unfortunately, after doing this, the same error still occurred.
How do I resolve this ImportError
?