Reputation: 303
I have a setup.py file below and I
maindir
|- setup.py
|-src
|- __init__.py
|- pipeline.py
|- parameter.py
and
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
classifiers=[
'Programming Language :: Python',
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License (GPL)'
],
packages=setuptools.find_packages(),
license='LICENSE.txt',
long_description=open('README.md').read(),
entry_points={'console_scripts': ['step1 = src.pipeline:step1']}
)
where pipeline.py
has import parameter
at the top.
I ran python setup.py install
but afterwards it said it couldn't find the module parameter.py
. So then instead of using packages = find_packages()
I used packages=['src/parameter','src']
but then I have to change import parameter
to import src.parameter
. Is there anyway to avoid this?
Upvotes: 0
Views: 1322
Reputation: 94397
You don't have any packages under src
so find_packages()
doesn't find any. Listing 'src/parameter'
as a package is meaningless as it's not a package (a directory with file __init__.py
), it's a module. Only 'src'
is a package here.
I have to change
import parameter
toimport src.parameter
Python 3, I suppose? Python 3 prefers absolute import but allows relative import. So either use import src.parameter
or import .parameter
import parameter
is an absolute import in Python 3 (in Python 2 it was relative+absolute import), i.e. Python searches through sys.path
to find parameter
and fails.
Upvotes: 1