简体   繁体   中英

Why does my Python distribution install each package in its own directory in site-packages?

I created a distribution package called myapi-1.0.0.tar.gz that has two python packages inside it (api and helpers). When I pip install it in my virtual environment, it api and helpers python packages are installed into their own folder in the root site-packages, instead of all being installed in a myapi folder.

This is the file structure of my project:

myapi/
├── api
│   ├── api.py
│   └── __init__.py
├── dist
│   ├── myapi-1.0.0-py3-none-any.whl
│   └── myapi-1.0.0.tar.gz
├── helpers
│   ├── helper_1.py
│   └── __init__.py
├── __init__.py
├── pyproject.toml
├── setup.cfg
└── setup.py

After running pip install myapi-1.0.0.0.tar.gz , pip list shows that myapi version 1.0.0 is installed.

However in .venv/lib/python3.8/site-packages , these folders are created:

myapi/.venv/lib/python3.8/site-packages/api/*
myapi/.venv/lib/python3.8/site-packages/helpers/*
myapi/.venv/lib/python3.8/site-packages/myapi-1.0.0.dist-info/

For every package and sub package I have in my project, when installed as a distribution package with pip, they are installed into the root of site-packages .

How do I get my distribution package to install all the packages and files as they exist in my project under the folder 'myapi' in site-packages ?

note that all __init__.py files and helper_1.py/api.py are empty.

setup.cfg:

[metadata]
name = myapi
version = 1.0.0

[options]
packages = find:

setup.py

import setuptools
setuptools.setup()

pyproject.toml

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

I have setup.py present in the project to allow me to create an editable installation, and pyproject.toml there to satisfy PEP standards, while most of the other configuration I try to put into setup.cfg

Change your file structure to the following.

myapi/
├── myapi/
│   ├── api
│   │   ├── api.py
│   │   └── __init__.py
│   ├── helpers
│   │   ├── helper_1.py
│   │   └── __init__.py
│   └── __init__.py
├── pyproject.toml
├── setup.cfg
└── setup.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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