如何在Ubuntu 18.04上使用--enable-shared配置python

时间:2018-11-25 01:23:24

标签: python-3.x heroku flask mod-wsgi ubuntu-18.04

我有一个Flask应用程序,我正尝试将其部署到heroku。我正在尝试通过运行ubuntu 18.04的虚拟盒子来做到这一点。

执行命令:git push heroku master

我看到警告:

WARNING: The Python installation you are using does not appear to have  
  been installed with a shared library, or in the case of MacOS X, as a
  framework. Where these are not present, the compilation of mod_wsgi may
  fail, or if it does succeed, will result in extra memory being used by all 
  processes at run time as a result of the static library needing to
   be loaded in its entirety to every process. It is highly recommended
   that you reinstall the Python installation being used from source code,
   supplying the '--enable-shared' option to the 'configure' script when
    configuring the source code prior to building and installing it.

,它失败并显示错误消息:

/usr/bin/ld: final link failed: Bad value
remote:            collect2: error: ld returned 1 exit status
remote:            error: command 'gcc' failed with exit status 1

我了解我需要在“配置”脚本中使用--enable-shared标志安装python。但我似乎在bin或python文件夹下的python安装中根本找不到配置脚本。这是我停滞了三天以来令人沮丧的地方;我真的不知道如何使用这样的标志来重新安装python ..在经历了很多帖子之后,我尝试了以下步骤:

1)从以下网址下载了python:https://www.python.org/downloads/source/

2)运行命令:./configure --prefix = / opt / python --enable-shared

之后是

并进行安装

3)将共享库文件复制到我的原始python目录中

命令的输出:ldd ** path ** / anaconda3 / bin / python给我:

libpython3.6m.so.1.0 => /usr/anaconda3/bin/../lib/libpython3.6m.so.1.0 
(0x00007f902dd2e000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 
(0x00007f902db0e000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f902d906000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f902d6fe000)
 librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f902d4f6000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f902d156000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f902cd5e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f902e26e000)

但是,当我尝试部署应用程序时,我看到--enable-shared的相同警告和gcc的相同错误消息。我似乎无法弄清楚如何正确地使我的python安装具有共享库。请注意,我是ubuntu的新手,非常感谢能解决此问题的任何线索。

P.S:我的mod_wsgi安装成功,并且能够通过mod_wsgi在本地运行该应用程序。

1 个答案:

答案 0 :(得分:0)

如果您不需要使用python3的自定义版本,则可以尝试通过apt安装python3.6-dev软件包,它为我添加了共享库。