I want to use a setup.py
which imports from a script which is part of the package that has to be installed. This script just contains a dict
that contains the strings for creating entry points. I haven't hardcoded them in the setup.py
because I want to use this list again later from the installed package.
Just for clearance here my directory structure and important files:
PackageA
|_package_a
| |_models
| |_modules
| | |_do_query.py
| | |_...
| |_setup_cfg.py
| |_ __init__.py
| |_...
|_ __init__.py
|_setup.py
__init__.py
in package_a
:
from .setup_cfg import setup_config
setup_cfg.py
:
setup_config = {
'scripts': [
'do_query'
]
}
setup.py
:
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
from .package_a import setup_config
with open('README.rst') as f:
readme = f.read()
with open('LICENSE') as f:
license = f.read()
setup(
...,
entry_points={
'console_scripts': ['{}=package_a.modules.{}:main'.format(script, script) for script in setup_config.get('scripts')]
},
)
I can make the import from .package_a import setup_config
and pycharm resolves this import correctly. However, if I try to install the package via pip3 install .
it fails with ModuleNotFoundError: No module named '__main__.package_a'; '__main__' is not a package
(we use pip
instead of python setup.py install
as we want to have the whole source folder installed in site-packages instead of a bundled version)
Can anyone explain me that exception or provide a proper way to achieve such a configuration? (The dict in setup_config.py
must be accesible from setup.py
as well when importing the installed package.
*
from directory. you can use such import method in file only. i.e. you can usefrom .package_a.modules._do_query import *
– Fulllengthsetup.py
, focuses on the version number but the techniques should work equally well for a dict: packaging.python.org/en/latest/guides/… – Chairman