简体   繁体   中英

Cython embed binary (docker): Failed to import the site module

I'm building Hello World using cython embed. Using docker python-3.5.3 image (Debian Jessie, with libpython3.5-dev additionaly installed)

hello.py:

print('hello world')

building:

cython --embed -o hello.c hello.py
gcc -I /usr/include/python3.5 -o hello hello.c -lpython3.5m

After trying to run i get ImportError:

Failed to import the site module
Traceback (most recent call last):
  File "/usr/lib/python3.5/site.py", line 580, in <module>
    main()
  File "/usr/lib/python3.5/site.py", line 566, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/lib/python3.5/site.py", line 253, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var
    return get_config_vars().get(name)
  File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix
    from _sysconfigdata import build_time_vars
  File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module>
    from _sysconfigdata_m import *
ImportError: No module named '_sysconfigdata_m'

I suggest that something is wrong with PATH or PYTHONPATH, but launching binary file with directly set environment fails with same error.

I used

find / -name '_sysconfigdata_m.py' 

/usr/lib/python3.5/plat-x86_64-linux-gnu/_sysconfigdata_m.py

And then

cp /usr/lib/python3.5/plat-x86_64-linux-gnu/_sysconfigdata_m.py /usr/lib/python3.5 Everything worked fine. 

But I still wonder - why _sysconfigdata_m is not placed in /usr/lib/python3.5 by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM