OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

python: "from library import module" works, but "import library.module" could not be resolved

  • Thread starter Thread starter Ozeta
  • Start date Start date
O

Ozeta

Guest
I've got this dts:

Code:
Pipfile
module-common\
  __init__.py
  setup.py
  common\
    library-common.py
module-a\
  __init__.py
  setup.py
  functional-module\
    library-a.py
    library-b.py

Pipfile is defined as

Code:
...
[packages]
module-common = {file = "module-common", editable = true}
module-a = {file = "module-a", editable = true}

setup.py are defined as

Code:
from setuptools import find_packages, setup

setup(
    name="module-common",
    version="2",
    ...
    packages=find_packages(),
    ...
)

and

Code:
from setuptools import find_packages, setup

setup(
    name="module-a",
    version="2",
    ...
    packages=find_packages(),
    ...
)

init.py files are empty

I installed all with

Code:
pipenv install -e module-common
pipenv install -e module-a
pipenv install

pip list is correctly showing my packages into the dts

so, in library-a I want to use a function from library-common,

but this declaration of library-a fails

Code:
from common.library-common import SomeClass
print(f"function return: {SomeClass.function()}")

and results in:

Code:
NameError: name 'library-common' is not defined

but if I declare

Code:
import common
print(f"function return: {common.common-function.SomeClass.function()}")

I got the correct answer.

what am I missing here? how do I get first notation to work?

the purpose is trying not touch library-a code, leave the imports as they are to avoid refactoring the whole codebase
<p>I've got this dts:</p>
<pre><code>Pipfile
module-common\
__init__.py
setup.py
common\
library-common.py
module-a\
__init__.py
setup.py
functional-module\
library-a.py
library-b.py

</code></pre>
<p>Pipfile is defined as</p>
<pre><code>...
[packages]
module-common = {file = "module-common", editable = true}
module-a = {file = "module-a", editable = true}

</code></pre>
<p>setup.py are defined as</p>
<pre><code>from setuptools import find_packages, setup

setup(
name="module-common",
version="2",
...
packages=find_packages(),
...
)

</code></pre>
<p>and</p>
<pre><code>from setuptools import find_packages, setup

setup(
name="module-a",
version="2",
...
packages=find_packages(),
...
)

</code></pre>
<p><strong>init</strong>.py files are empty</p>
<p>I installed all with</p>
<pre class="lang-bash prettyprint-override"><code>pipenv install -e module-common
pipenv install -e module-a
pipenv install
</code></pre>
<p><code>pip list</code> is correctly showing my packages into the dts</p>
<p>so, in library-a I want to use a function from library-common,</p>
<p>but this declaration of library-a fails</p>
<pre><code>from common.library-common import SomeClass
print(f"function return: {SomeClass.function()}")
</code></pre>
<p>and results in:</p>
<pre><code>NameError: name 'library-common' is not defined
</code></pre>
<p>but if I declare</p>
<pre><code>import common
print(f"function return: {common.common-function.SomeClass.function()}")
</code></pre>
<p>I got the correct answer.</p>
<p>what am I missing here? how do I get first notation to work?</p>
<p>the purpose is trying not touch library-a code, leave the imports as they are to avoid refactoring the whole codebase</p>
 

Latest posts

B
Replies
0
Views
1
Blundering Ecologist
B
Top