Python包安装后子文件夹及文件缺失的问题修正方案咨询
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:
- Create a
MANIFEST.infile in your project root (same directory assetup.py) with these lines:
include ppackage/nickname_override.py recursive-include ppackage/sub_file *
- Update your
setup.pyto 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

