简体   繁体   English

Python打包:未安装子目录

[英]Python packaging: subdirectories not installed

I have a Python project with the layout 我有一个带有布局的Python项目

setup.py
foobar/
    __init__.py
    foo.py
    bar/
        __init__.py

Where the foobar/__init__.py reads foobar/__init__.py读取的位置

from . import foo
from . import bar

and setup.py setup.py

from setuptools import setup

setup(
    name='foobar',
    version='0.0.1',
    packages=['foobar'],
    )

When doing import foobar from the source directory, it all works as expected. 从源目录执行import foobar ,它都按预期工作。 However, when installing the package via pip install . 但是,通过pip install .安装软件包时pip install . , the subfolder bar/ is not installed, leading to the import error ,子文件夹bar/ 安装,导致导入错误

ImportError: cannot import name bar

Any hints? 任何提示?

Apparently to include subpackages, you need find_packages() : 显然要包含子包,你需要find_packages()

from setuptools import setup, find_packages

setup(
    name='foobar',
    version='0.0.1',
    packages=find_packages()
    )

This is recommended​ in the setuptools docs as well. 这也是setuptools文档中的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM