python setup.py 安装,virtualenv 内存不足
python setup.py install, out of memory in virtualenv
我正在编写一个 Python 包,其中包含一些 Cython 代码。我使用虚拟环境。当我写
时它编译得很好
$ 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
中,有一个软件 link(我在 Linux)到位于
位置的文件夹
../../DATA
即软link是
ColoredHRG/ColoredHRG/examples/DATA -> ../../DATA
事实证明,不知何故,这导致 distutils 进入无限递归循环,吃掉我计算机的全部内存,然后挂起。
我删除了软件link,现在一切正常。
编辑:更正错别字。
我正在编写一个 Python 包,其中包含一些 Cython 代码。我使用虚拟环境。当我写
时它编译得很好$ 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
中,有一个软件 link(我在 Linux)到位于
../../DATA
即软link是
ColoredHRG/ColoredHRG/examples/DATA -> ../../DATA
事实证明,不知何故,这导致 distutils 进入无限递归循环,吃掉我计算机的全部内存,然后挂起。
我删除了软件link,现在一切正常。
编辑:更正错别字。