You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python包安装后子文件夹及文件缺失的问题修正方案咨询

Fix Missing Subfolder and File in Installed Python Package

Alright, let's get your sub_file subfolder and nickname_override.py file showing up properly after installation. Here are the specific changes you need to make to your setup.py and related files:

1. Use find_packages() for Automatic Package Discovery

Instead of manually listing packages, let setuptools handle finding all valid subpackages automatically. This ensures ppackage.sub_file is always included as long as it follows Python package conventions:

from setuptools import setup, find_packages
setup(
    name='ppackage',
    version='0.0.111',
    description='make life easier',
    author='testx',
    packages=find_packages(),  # Replaces your manual package list
)

2. Ensure sub_file is a Valid Python Package

Make sure the sub_file folder contains an empty __init__.py file. Setuptools only recognizes folders with this file as proper Python packages—without it, the folder won't be installed even if you list it manually in packages.

3. Include nickname_override.py in the Package Distribution

If nickname_override.py is part of your package (e.g., inside ppackage or ppackage.sub_file), you need to explicitly tell setuptools to include it. You have two straightforward options:

Option A: Use package_data directly in setup.py

Add this parameter to your setup() call to specify extra files per package:

from setuptools import setup, find_packages
setup(
    name='ppackage',
    version='0.0.111',
    description='make life easier',
    author='testx',
    packages=find_packages(),
    package_data={
        # Include nickname_override.py if it's in the root ppackage folder
        'ppackage': ['nickname_override.py'],
        # Include all files in sub_file (adjust the pattern if you only need specific ones)
        'ppackage.sub_file': ['*'],
    },
)

Option B: Use include_package_data with a MANIFEST.in File

This is cleaner if you have multiple extra files to include:

  1. Create a MANIFEST.in file in your project root (same directory as setup.py) with these lines:
include ppackage/nickname_override.py
recursive-include ppackage/sub_file *
  1. Update your setup.py to enable using the manifest file:
from setuptools import setup, find_packages
setup(
    name='ppackage',
    version='0.0.111',
    description='make life easier',
    author='testx',
    packages=find_packages(),
    include_package_data=True,  # Tells setuptools to follow rules in MANIFEST.in
)

Final Check

After making these changes, uninstall the existing package first with:

pip uninstall ppackage

Then reinstall using your updated setup:

pip install --upgrade git+git://github.com/balandongiv/driving_tools.git

Your sub_file folder and nickname_override.py should now appear in the installed package directory.

内容的提问来源于stack exchange,提问作者rpb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 19:22:40