Cython嵌入二进制文件(docker):无法导入站点模块

时间:2017-01-30 15:21:44

标签: python python-3.x docker cython

我正在使用cython嵌入构建Hello World。使用docker python-3.5.3镜像(Debian Jessie,安装了libpython3.5-dev)

hello.py:

print('hello world')

建筑:

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

尝试运行后我得到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'

我建议PATH或PYTHONPATH出现问题,但启动直接设置环境的二进制文件会出现同样的错误。

1 个答案:

答案 0 :(得分:0)

我用过

find / -name '_sysconfigdata_m.py' 

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

然后

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

但我仍然想知道 - 为什么_sysconfigdata_m默认不放在/usr/lib/python3.5中。