简体   繁体   中英

setup.py is installing into the root of folder site-packages

Yes, I'm new to Python packaging but not new to Python. A package I have developed has subpackages - say 'formats' and 'toolbox'. My code is in a repository under Gitlab. The server's address is https://git.wur.nl

On my computer I have several Python instances. To be sure I invoke the right instance of pip, I move to where it is installed - in subfolder Scripts. To install my package on my Windows machine, I therefore type:
C:\\Python36\\Scripts\\pip install git+https://git.wur.nl/myname/mypkg

The installation then seems to go well. I'd expect that my code would end up in directory C:\\Python36\\Lib\\site-packages\\mypkg, ie with subfolders 'formats' and 'toolbox' below folder mypkg. Unfortunately, the folders 'formats' and 'toolbox' end up in the root of C:\\Python36\\Lib\\site-packages. When I try to import mypkg in a Python script or so, I'm told that package mypkg does not exist - no surprise. Below is the code of module setup.py ...

What is going wrong here?

from setuptools import setup, find_packages
import os

PACKAGE = "mypkg"
NAME = "Mypkg"
DESCRIPTION = 'Python raster GIS library with low memory requirements.' 
AUTHOR = "Dobedani"
AUTHOR_EMAIL = 'dobedani@xyz.nl'
URL = 'https://git.wur.nl/myname/mypkg/'
LICENSE="LGPL"
VERSION = "1.0"

here = os.path.abspath(os.path.dirname(__file__))

long_description = 'Python raster GIS library with low memory requirements.'

setup(
    name=NAME,
    version=VERSION,
    url=URL,
    download_url='https://git.wur.nl/dobedani/mypkg/-/archive/master/mypkg-master.tar.gz',
    license='LGPL',
    author=AUTHOR,
    install_requires=['pyshp>=2.1.0',
                      'pyproj>=1.9.5.1',
                      'numpy>=1.14.3',
                      'tifffile>=2019.3.18',
                      'tables>=3.5.2',
                      'netCDF4>=1.5.1.2',
                      'libtiff>=0.4.2'],
    author_email=AUTHOR_EMAIL,
    description=DESCRIPTION,
    long_description=long_description,
    packages=find_packages(), 
    include_package_data=True,
    platforms='any',
    test_suite='mypkg.tests.make_test_suite',
    classifiers=[
        'Development Status :: 4 - Beta',
        'Environment :: Console',
        'Intended Audience :: Developers',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: GNU Lesser General Public License v3.0 (LGPL 3.0)',
        'Natural Language :: English',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Topic :: Scientific/Engineering']
)

The following gives an idea of the structure of the package:

mypkg  
  formats/
    __init__.py
    asciigrid.py
  toolbox/
    __init__.py
    cliplib.py
  setup.py
  README.md
  requirements.txt
  MANIFEST.in
  LICENSE

There is confusion about what the top level packages of the project are.

If you want the top level package to be mypkg and the code to be importable like in the following:

import mypkg
# or
from mypkg import formats
from mypkg import toolbox

then the appropriate directory structure is:

mypkg/
  mypkg/
    __init__.py
    formats/
      __init__.py
      asciigrid.py
    toolbox/
      __init__.py
      cliplib.py
  setup.py
  README.md
  requirements.txt
  MANIFEST.in
  LICENSE

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