The following operations is under Win10:
- the dictionary structure:
│ LICENSE
│ README.md
│ setup.py
│
└─dlpk
a.py
b.py
__init__.py
- the contents of the files:
the __init__.py is empty.
# b.py:
from a import A
# a.py:
class A:
pass
# setup.py:
import setuptools
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name="testDL-DeaL",
version="0.0.9",
author="Dai Ling",
author_email="[email protected]",
description="error report",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/dailing57/DLex",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
packages=setuptools.find_packages(),
python_requires=">=3.6",
)
- Execute following commands:
python setup.py sdist
twine upload --repository testpypi dist/*
- Import it from the test.pypi create and activate the venv
do
pip install --index-url https://test.pypi.org/simple/ --no-deps testDL-DeaL==0.0.9
write a test file: test.py:
from dlpk import b
and run it, it shows:
Traceback (most recent call last):
File "H:\DLang\TEST\test.py", line 1, in <module>
from dlpk import b
File "H:\DLang\TEST\venv\lib\site-packages\dlpk\b.py", line 1, in <module>
from a import A
ModuleNotFoundError: No module named 'a'
How does this error happen?
lang-py
from a import Amust be changed to eitherfrom dlpk.a import A(absolute import) orfrom .a import A(relative import).ModuleNotFoundError: No module named 'dlpk'forfrom dlpk.a import AandImportError: attempted relative import with no known parent packageforfrom .a import Aimport dlpkand thenprint(dlpk)to verify the thing you are trying to import is in fact the one you are expecting. You should also use a virtual environment while developing to constrain the issue (and make it easier for you to isolate the issue which you can do by creating a new one and optionally deleting the old one).