Я упаковываю свой первый проект Python, и у меня в подкаталоге хранятся два файла со вспомогательными функциями: Comments.py и Score.py.
YT_Sentiments/
└── src/
├── YT_Sentiments/
│ ├── helpers/
│ │ ├── __init__.py
│ │ ├── score.py
│ │ └── comments.py
│ ├── __init__.py
│ └── main.py
├── LICENSE
├── pyproject.toml
├── README.md
└── setup.py
в мой main.py я импортирую два файла
from helpers import score
from helpers import comments
Когда я собираю и устанавливаю его локально, я получаю сообщение об ошибке:
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\YT_Sentiments\main.py", line
1, in
from helpers import score
ModuleNotFoundError: No module named 'helpers'
Я просмотрел как минимум 4 руководства по упаковке и реализовал то, что, как мне казалось, могло решить мою проблему (setup.py и pyproject.toml)
setup. py
from setuptools import find_packages, setup
with open("README.md") as f:
long_description = f.read()
setup(name = "YT_Sentiments",
version = "0.0.4",
description = "analyze comments from any youtube video!",
package_dir = {"":"YT_Sentiments"},
packages = find_packages(where="YT_Sentiments"),
long_description=long_description,
long_description_content_type="text/markdown",
license = "MIT",
classifiers=[
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules",
"Operating System :: OS Independent",
],
install_requires = ["emoji>=2.12.1",
"google_api_python_client>=2.139.0",
"vaderSentiment>=3.3.2",
"vaderSentiment>=3.3.2",],
python_requires = ">=3.8",
)
pyproject.toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "YT_Sentiments"
version = "0.0.4"
description = "A python package that allows you to perform sentiment analysis on Youtube comments"
readme = "README.md"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
"emoji>=2.12.1",
"google_api_python_client>=2.139.0",
"vaderSentiment>=3.3.2",
"vaderSentiment>=3.3.2",
]
[project.urls]
Homepage = "https://github.com/pypa/sampleproject"
Issues = "https://github.com/pypa/sampleproject/issues"`
Подробнее здесь: https://stackoverflow.com/questions/788 ... on-project