简体   繁体   中英

setup.py not packaging application

Windows 10

Python 3.10.4

I have a very basic python package linked here for reference: https://github.com/Edouard87/example-python-package .

The structure is this:

example_package/
|-- setup.py
ˋ-- src/
    ˋ-- example_pkg/
        |-- __init__.py
        |-- module1.py

My setup.py looks like this:

from setuptools import setup

setup(
    name        = "example_package",
    package_dir = {"example_pkg": "src"},
    packages    = ["example_pkg"]
)

module1.py looks like this:

def func_1():
    print("imported")

def cli():
    print("ran cli.")

class TestClass:
    def test_method(self):
        print("test!")

__init__.py is empty.

I want to be able to import example_pkg into the python interpreter. Because I don't want to have permissions issues with my global python interpreter, I'm using a venv and I made sure to activate it.

I run pip install -e. . Then I run pip list which gives me:

example-package 0.0.0   c:\users\me\documents\python\example_package\.venv\lib\site-packages
pip             22.0.4

Now, I launch python and in the REPL I run:

import example_pkg

This gives me a ModuleImportError . I looked into lib/site-packages and the .egg-link s are there and are pointing to the correct directories.

I don't understand why this isn't working. Can anyone point to something I'm missing?

Fix:

package_dir = {'': 'src'}

See https://docs.python.org/3/distutils/setupscript.html#listing-whole-packages :

" The keys to this dictionary are package names, and an empty package name stands for the root package . " — emphasize mine ( phd ).

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