Solved: import from parent directory in python setup

py

The main problem is that setup.py does not allow you to import modules from a parent directory.

.py

from setuptools import setup, find_packages

setup(name='mypackage',
      version='1.0',
      description='My package',
      url='https://github.com/myusername/mypackage',
      author='My Name',
      author_email='myemail@example.com',
      license='MIT',
      packages=find_packages(),  # include all packages under src directory
)

This code is setting up a Python package. The first line imports the setup and find_packages functions from the setuptools module. The setup function is used to configure the package. The name, version, description, url, author, author_email, and license arguments are all required. The packages argument tells setup which packages to include in the package. In this case, it includes all packages under the src directory.

import

import is a keyword in Python that allows you to load modules from a file. When you import a module, the module’s definitions and functions are made available to the current scope.

parent directory

A parent directory is a directory that is above the current working directory. In Python, the parent directory is always the root directory.

Related posts:

Leave a Comment