简体   繁体   English

pyproject.toml/setuptools 将文件复制到根站点包目录中

[英]pyproject.toml/setuptools duplicates files into root site-packages directory

I have a problem with how pip/setuptools is installing my package. When installing from the project directory (ie pip install. ) my project's sub-packages are duplicated and placed in the root site-packages directory.我对 pip/setuptools 如何安装我的 package 有疑问。从项目目录(即pip install. )安装时,我的项目的子包被复制并放置在根站点包目录中。 The configuration is set entirely within pyproject.toml (with a minimal setup.py for compiling a single extension).配置完全在pyproject.toml中设置(使用最小的setup.py来编译单个扩展)。

If my package is named mypackage which contains 3 sub-packages and depends on 3 dependencies, this is the expected directory structure under site-packages in the venv:如果我的 package 名为mypackage ,它包含 3 个子包并依赖 3 个依赖项,这是 venv 中 site-packages 下的预期目录结构:

site-packages
    - dependency1
    - dependency2
    - dependency3
    - myproject
        - subpackage1
        - subpackage2
        - subpackage3

Yet below is what I end up with, it looks like any folder containing any.py files are copied to root site-packages (ie including the venv itself and docs since they contain py files:然而下面是我最终得到的结果,它看起来像任何包含 any.py 文件的文件夹都被复制到根站点包(即包括 venv 本身和文档,因为它们包含 py 文件:

site-packages
    - dependency1
    - dependency2
    - dependency3
    - mypackage
        - subpackage1
        - subpackage2
        - subpackage3
    - subpackage1
    - subpackage2
    - subpackage3
    - docs
    - venv

What can I do to avoid duplicating sub-packages into the top-level site-packages directory/install correctly?我该怎么做才能避免将子包复制到顶级站点包目录/正确安装?

Here is my project structure:这是我的项目结构:

myproject/
    - pyproject.toml
    - setup.py
    - docs/
    - myproject/
        - __init__.py
        - subpackage1/
        - subpackage2/
        - subpackage3/
    - venv/

The reduced contents of pyproject.toml pyproject.toml的缩减内容

[project]
name = "myproject"
requires-python = ">= 3.7"
dependencies = [
    "dependency1",
    "dependency2",
    "dependency3",
]

[tool.setuptools]
packages = [
    "myproject",
    "myproject.subpackage1",
    "myproject.subpackage2",
    "myproject.subpackage3",
    ]

[build-system]
requires = ["setuptools >= 61.0.0", "cython"]
build-backend = "setuptools.build_meta"

The contents of setup.py : setup.py的内容:

from setuptools import Extension, setup
from Cython.Build import cythonize


ext_modules = [
    Extension(
        "subpackage1.func",
        ["..."],
        extra_compile_args=['-fopenmp'],
        extra_link_args=['-fopenmp'],
    )
]


setup(ext_modules=cythonize(ext_modules))

I've just ran into the same issue.我刚刚遇到了同样的问题。

In my case, the build directory used by pip was polluted with the "subfolders", probably because of a previous run where my package discovery settings were erroneous.在我的例子中, pip使用的build目录被“子文件夹”污染了,这可能是因为之前运行时我的 package 发现设置是错误的。 Because of this, although my configuration was (now) correct, these orphaned directories were copied to my site-packages as well.因此,虽然我的配置(现在)是正确的,但这些孤立的目录也被复制到我的site-packages中。

In my case the build directory was in the folder where I called pip install.在我的例子中, build目录位于我调用pip install. from.从。

If you want to find the build directory, or just check whether this is the problem, log pip's output to a file with pip install. --log foo.txt如果您想找到build目录,或者只是检查这是否是问题所在,请将 pip 的 output 记录到带有pip install. --log foo.txt pip install. --log foo.txt , and search for copying inside. pip install. --log foo.txt ,然后在里面搜索copying You should see a line like:你应该看到一行:

Arguments: ('copying', '<build directory>\\lib\\subpackage1\\bar.py', ...

Hope this helps!希望这可以帮助!

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

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