-2

Hi have created a wheel file and installed it. But upon importing I'm getting module not found error.

Here is the Setup.py

import setuptools
from setuptools import find_packages
import pathlib, os
root=pathlib.Path(__file__).parent
os.chdir(str(root))
with open("README.md", "r", encoding="utf-8") as fh:
  long_description = fh.read()

setuptools.setup(
name='testai',
version='0.1.0',
author='test',
author_email='test@test.ai',
description='Testing installation of Package',
long_description=long_description,
long_description_content_type="text/markdown",
package_dir={"": "testai"},  # Optional

packages=find_packages(where="testai"),  # Required

url='',#need to add url
project_urls = {
    "Bug Tracker": "https://github.com/"#need to add issues url
},
license='MIT',#need to decide which licence to give
install_requires=['requests','aiohttp','pydantic','urllib3','boto3','gcloud','google-cloud- 
storage','aiocache','databases'],#list packages
classifiers=[
    "Development Status :: 1 - Planning",
    "Intended Audience :: Developers",
    "Operating System :: Unix",
    "Operating System :: MacOS :: MacOS X",
    "Operating System :: Microsoft :: Windows",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3.7",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: 3 :: Only",
]
)

My folder structure is:

testai(base-dir)
|__>testai(dir with code)
   |__>src(dir)
       |__>core(dir)
          |__>config.py
          |__>__init__.py
       |__>storage(dir)
          |__>dummystorage.py 
          |__>__init__.py
       |__>__init__.py(contains all the imports)
|__>__init__.py
|__>setup.py
|__>README.md

I can't understand why my import fails but the package is present.

On doing pip show testai, it gives all the info.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • have you tried with python or python3 command to run the same code? In some cases, modules are installed for python2 and we try to run with python3 or vice versa. – Shyam Bhattacharyya Nov 16 '22 at 04:57
  • I tried with python3, python2 is not installed. – Prateek Singh Nov 16 '22 at 05:06
  • 1
    Your project directory and file structure is not correct. I recommend you follow this tutorial: https://packaging.python.org/en/latest/tutorials/packaging-projects/#creating-the-package-files -- In short you need to rename `testai` to `src` and `testai/src` to `src/testai`, and then in your `setup.py` you need: `package_dir={"": "src"}` and `packages=find_packages(where="src")`. – sinoroc Nov 16 '22 at 10:07

1 Answers1

-2

As pointed out by @sinoroc, my folder structure was wrong, inside my src directory, I put my package. So in the end my folder structure was looking like this.

testai(base-dir)
|__>src(dir)
   |__>testai
    |__>core(dir)
      |__>config.py
      |__>__init__.py
    |__>storage(dir)
      |__>dummystorage.py 
      |__>__init__.py
    |__>__init__.py(contains all the imports)
|__>__init__.py
|__>setup.py
|__>README.md