0

The following operations is under Win10:

  1. the dictionary structure:
│ LICENSE
│ README.md
│ setup.py
│
└─dlpk
 a.py
 b.py
 __init__.py
  1. 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",
)
  1. Execute following commands:
python setup.py sdist
twine upload --repository testpypi dist/*
  1. 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?

asked Mar 21, 2022 at 4:41
6
  • As per the linked questions, the statement from a import A must be changed to either from dlpk.a import A (absolute import) or from .a import A (relative import). Commented Mar 21, 2022 at 4:46
  • but it will report ModuleNotFoundError: No module named 'dlpk' for from dlpk.a import A and ImportError: attempted relative import with no known parent package for from .a import A Commented Mar 21, 2022 at 4:52
  • That second error means you have not install the package into the currently active Python environment. Commented Mar 21, 2022 at 4:53
  • I develope it under the global python environment. Does it mean that I should install the developing package to the global environment? Commented Mar 21, 2022 at 11:30
  • The python you are running may be picking up a mix of the installed package and the developed package, possibly because of where your current working directory is. I cannot seem to replicate your issue. Try doing a import dlpk and then print(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). Commented Mar 22, 2022 at 3:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.