How to structure python packages without repeating top level name for import

后端 未结 3 1348
执笔经年
执笔经年 2020-12-13 04:58

I\'m brand new at python package management, and surely have done something wrong. I was encouraged to create a directory structure as follows:

bagoftricks
         


        
3条回答
  •  粉色の甜心
    2020-12-13 05:08

    Follow following structure :

    bagoftricks 
        ── bagoftricks
        │ ├── __init__.py
        │ └── bagoftricks.py 
        ├── README.md
        └── setup.py
    

    and then you should be able to use it as :

    from bagoftricks.bagoftricks import levenshtein, geofind
    

    but after you make the change in folder structure do :-

    pip uninstall 
    

    and reinstall the package

    meanwhile check your setup.py

    #!/bin/env python
    import os.path
    from setuptools import setup, find_packages
    
    def current_path(file_name):
        return os.abspath(os.path.join(__file__, os.path.pardir, file_name))
    
    setup(
        name = 'bagoftricks',
        version = '0.1',
        include_package_data = True,
        packages=find_packages(),
    )
    

    setup might have some other parameters too. I hope it works for you.

提交回复
热议问题