python setup.py 安装,virtualenv 中内存不足

标签 python installation cython distutils

我正在编写一个包含一些 Cython 代码的 Python 包。我使用虚拟环境。当我编写时它编译得很好

$ source activate
$ python setup.py build_ext --inplace

但是,当我尝试安装该软件包时,它开始消耗内存,直到我的计算机挂起(或者我之前终止了该进程)。更具体地说,当我尝试时它会挂起:

$ python setup.py install
running install
running bdist_egg
running egg_info
creating ColoredHRG.egg-info
writing ColoredHRG.egg-info/PKG-INFO
writing top-level names to ColoredHRG.egg-info/top_level.txt
writing dependency_links to ColoredHRG.egg-info/dependency_links.txt
writing manifest file 'ColoredHRG.egg-info/SOURCES.txt

我认为有以下[ https://github.com/docker/docker/issues/10025][1]可能是问题的根源。本质上,在上面引用的问题中,它说了以下内容

I can replicate this issue. The above resolution does not suggest that changing Python versions fixed anything. It's the writing of files by setuptools that's causing it, though I don't know why. Sometimes it hangs for me when writing dependency_links.txt and sometimes SOURCES.txt. Will see if I can investigate further.

...

Haha, ok, the issue is that you're calling setup.py from / and distutils does a listdir('.') from the calling directory, so I assume it's walking the entire filesystem. So I guess, don't do that. https://github.com/python/cpython/blob/master/Lib/distutils/filelist.py#L245

我知道发生了什么,但我不知道如何解决问题。

可能有用的更多信息。下面是setup.py

的内容
from setuptools import setup
from Cython.Build import cythonize

setup( name = 'ColoredHRG' ,
       version = '0.1' ,
       description = 'my package.' ,
       url = 'BLA BLA' ,
       author = 'BLA BLA' ,
       author_email = 'BLA BLA' ,
       license = 'GPL3' ,
       packages = [ 'ColoredHRG' ] ,
       ext_modules = cythonize( [ "ColoredHRG/ColoredHRG.pyx" ,
                                  "ColoredHRG/Pool.pyx" , 
                                  "ColoredHRG/MC.pyx" , 
                                  "ColoredHRG/EXAMPLE_traveling_salesman.pyx" , 
                                  "ColoredHRG/MC_ColoredHRG.pyx" ] ,
                                  language = 'c++' ) ,
                                  zip_safe = False )

编辑:修正了错误的句子。

编辑:添加标志cython

最佳答案

终于找到问题所在了。包的文件夹结构如下

ColoredHRG/setup.py
...
ColoredHRG/ColoredHRG/ColoredHRG.pyx
ColoredHRG/ColoredHRG/MC.pyx
...
ColoredHRG/ColoredHRG/examples/examples.py
...

此外,在文件夹 examples 内,有一个软链接(soft link)(我在 Linux 中),指向该位置的文件夹

../../DATA

即软链接(soft link)是

ColoredHRG/ColoredHRG/examples/DATA -> ../../DATA

事实证明,不知何故,这会导致 distutils 进入无限递归循环,吃掉我计算机的整个内存,然后挂起。

我删除了软链接(soft link),现在一切正常。

编辑:更正拼写错误。

关于python setup.py 安装,virtualenv 中内存不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38104637/

相关文章:

python - 如何安装 PyInstaller?

c++ - Boost 构建 fatal error LNK1105

python - cython中的缓慢 split

python - 即使我正在链接必要的静态库,cython 模块也会引发 ImportError

python - 仅在 setup.py 中可能时编译可选的 cython 扩展

python - 使用 Python/Django 上传大文件

python - Pandas 在 Python 中将一些行转换为列

python - Spark窗口函数,根据数据集中的值创建排名列

python - pygtk : saving the project file with suffix ".xyz"

C# 安装类未执行