如何把安装包install成包括源文件的文件夹形式,而不是.egg这样的形式(setuptools中zip_safe设置为False)

主要参考

https://stackoverflow.com/questions/33014356/how-to-make-python-setup-py-install-install-source-instead-of-egg-file

说明

涉及到源码调试的东西多了,碰到安装成.egg的文件就不怎么好调试,我希望文件包安装完之后,所有的源文件都是解压后放在文件夹中的。

以这次更新gluoncv到最新安装包为例,比如,在这里把最新的gluoncv下载下来,

https://github.com/dmlc/gluon-cv

解压后切换到目录下用python setup.py install命令进行安装(mx36gpu是我在anaconda下的mxnet环境)

(mx36gpu) D:\mXNet\gluon-cv-master>python setup.py install

最后发现在D:\Anaconda3\envs\mx36gpu\Lib\site-packages文件夹下出现的是一个gluoncv-0.8.0-py3.6.egg文件,而不是一个文件夹。这样我在源码调试时,看上去非常不美观。

根据setuptools官网上的说明(参考https://setuptools.readthedocs.io/en/latest/setuptools.html#setting-the-zip-safe-flag),要把zip_safe改成False才行

修改后的setup.py文件内容如下,

#!/usr/bin/env python
import io
import os
import re
import sys

import numpy as np

try:
    from Cython.Build import cythonize
except ImportError:
    cythonize = None
from setuptools import setup, find_packages, Extension

with_cython = False
if '--with-cython' in sys.argv:
    if not cythonize:
        print("Cython not found, please run `pip install Cython`")
        exit(1)
    with_cython = True
    sys.argv.remove('--with-cython')


def read(*names, **kwargs):
    with io.open(
            os.path.join(os.path.dirname(__file__), *names),
            encoding=kwargs.get("encoding", "utf8")
    ) as fp:
        return fp.read()


def find_version(*file_paths):
    version_file = read(*file_paths)
    version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
                              version_file, re.M)
    if version_match:
        return version_match.group(1)
    raise RuntimeError("Unable to find version string.")


try:
    import pypandoc

    long_description = pypandoc.convert('README.md', 'rst')
except(IOError, ImportError):
    long_description = open('README.md').read()

VERSION = find_version('gluoncv', '__init__.py')

requirements = [
    'numpy',
    'tqdm',
    'requests',
    # 'mxnet',
    'matplotlib',
    'portalocker',
    'Pillow',
    'scipy',
]
if with_cython:
    _NP_INCLUDE_DIRS = np.get_include()

    # Extension modules
    ext_modules = cythonize([
        Extension(
            name='gluoncv.nn.cython_bbox',
            sources=['gluoncv/nn/cython_bbox.pyx'],
            extra_compile_args=['-Wno-cpp', '-O3'],
            include_dirs=[_NP_INCLUDE_DIRS]),
        Extension(
            name='gluoncv.model_zoo.rcnn.rpn.cython_rpn_target',
            sources=['gluoncv/model_zoo/rcnn/rpn/cython_rpn_target.pyx'],
            extra_compile_args=['-Wno-cpp', '-O3'],
            include_dirs=[_NP_INCLUDE_DIRS]),
    ])
else:
    ext_modules = []

setup(
    # Metadata
    name='gluoncv',
    version=VERSION,
    author='Gluon CV Toolkit Contributors',
    url='https://github.com/dmlc/gluon-cv',
    description='MXNet Gluon CV Toolkit',
    long_description=long_description,
    license='Apache-2.0',

    # Package info
    packages=find_packages(exclude=('docs', 'tests', 'scripts')),
    zip_safe=False,
    include_package_data=True,
    install_requires=requirements,
    ext_modules=ext_modules
)

然后再执行

(mx36gpu) D:\mXNet\gluon-cv-master>python setup.py install

在anaconda的文件夹下,就可以找到gluoncv-0.8.0-py3.6.egg解压后的文件夹。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值