.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

最後に、gluoncv-0.8.0-py3.6.eggファイルがフォルダーではなくD:\ Anaconda3 \ envs \ mx36gpu \ Lib \ site-packagesフォルダーに表示されていることがわかりました。そのため、ソースコードをデバッグすると、非常に見苦しく見えます。

setuptoolsの公式Webサイト(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の解凍されたフォルダーがあります。

おすすめ

転載: blog.csdn.net/tanmx219/article/details/107288708