gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:41 26 4
gpt4 key购买 nike

我正在编写一个包含一些 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com