0

I'm making a python library that has a __init__.py file that requires another python file in the same directory and for some reason when i try to import the library it says me that it couldn't find the other dependency.

This is my setup.py file:

from setuptools import setup, find_packages
 
classifiers = [
  "Development Status :: 5 - Production/Stable",
  "Intended Audience :: Education",
  "Intended Audience :: Developers",
  "Natural Language :: English",  
  "Operating System :: Microsoft :: Windows :: Windows 10",
  "Operating System :: MacOS :: MacOS X",
  "Operating System :: POSIX :: Linux",  
  "License :: OSI Approved :: MIT License",
  "Programming Language :: Python :: 3.6", 
  "Programming Language :: Python :: 3.7", 
  "Programming Language :: Python :: 3.8", 
  "Programming Language :: Python :: 3.9", 
  "Topic :: Software Development :: Libraries :: Python Modules", 
]
 
from os import path
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, "docs/README.md"), encoding="utf-8") as f:
    long_description = f.read()

with open('requirements.txt') as f:
    required = f.read().splitlines()

github_url = "https://github.com/Patitotective/PREFS"

setup(
  name="PREFS",
  version="0.1.5",
  author="Cristobal Riaga",
  author_email="cristobalriaga@gmail.com",
  maintainer="Cristobal Riaga", 
  maintainer_email="cristobalriaga@gmail.com",
  url=github_url,  
  project_urls={
    "Documentation": f'https://prefs-documentation.readthedocs.io/en/latest/', 
    'Source Code': github_url,
    'Changelog': f'{github_url}/blob/main/docs/CHANGELOG.md',
    'Issues': f'{github_url}/issues', 
    'Pull requests': f'{github_url}/pulls', 
    'Discussions': f"{github_url}/discussions"
  },
  description="Simple but useful python library that helps you to store and manage user preferences.",
  long_description=open("docs/README.md").read(),
  classifiers=classifiers,
  platforms= ["Windows", "Linux", "MacOS"],
  keywords=["prefs", "preferences"],  
  license="MIT", 
  packages=find_packages(),
  install_requires=required, 

  long_description_content_type="text/markdown"
)

These are the imports in my __init__.py file:

#Libraries
import os # To manage paths, folders and files
import json # To support export/import json files
import warnings # To send warnings
from os import path # To check if file or folder exists in path

#Dependencies
from readPREFS import ReadPREFS

And the directory looks like this:

├── CODE_OF_CONDUCT.md
├── Demo
│   └── demo.py
├── docs
│   ├── CHANGELOG.md
│   └── README.md
├── Images
│   └── logo1.png
├── LICENSE.txt
├── MANIFEST.in
├── PREFS
│   ├── docs.py
│   ├── example.py
│   ├── __init__.py
│   ├── readPREFS.py
│   ├── Test
│   │   ├── Prefs
│   │   │   ├── prefs1.json
│   │   │   ├── prefs1.prefs
│   │   │   └── prefs.json
│   │   ├── prefs1.prefs
│   │   └── test.py
│   └── Trial
│       └── trial.py
├── requirements.txt
├── setup.cfg
└── setup.py

(The dependency that __init__.py requires is called readPREFS.py)

PD: The library i'm working on is called PREFS.

Update: These two answers helped me to fix my error:

Patitotective
  • 35
  • 1
  • 7
  • This question answers my question: [https://stackoverflow.com/questions/65077663/building-a-python-wheel-no-module-named](https://stackoverflow.com/questions/65077663/building-a-python-wheel-no-module-named) . – Patitotective Jul 18 '21 at 12:03
  • Also this answer is useful https://stackoverflow.com/questions/16981921/relative-imports-in-python-3/49375740#49375740 – Patitotective Jul 18 '21 at 12:23

0 Answers0