Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__init__.py causes No module named 'adblock.adblock' #17

Open
The-Compiler opened this issue Dec 22, 2020 · 8 comments
Open

__init__.py causes No module named 'adblock.adblock' #17

The-Compiler opened this issue Dec 22, 2020 · 8 comments

Comments

@The-Compiler
Copy link
Contributor

The-Compiler commented Dec 22, 2020

After building via maturin build and installing the wheel via pip, running python3 -c "import adblock" results in:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/florian/tmp/python-adblock/adblock/__init__.py", line 1, in <module>
    from .adblock import __version__, Engine, FilterSet, BlockerResult, UrlSpecificResources
ModuleNotFoundError: No module named 'adblock.adblock'

This is because the adblock module gets imported, and due to from .adblock import, Python tries to import adblock.adblock.

When trying again outside of the git repository, the import works fine.

It looks like that adblock module is only required for type annotations? Is the __init__.py really required, and is the import even correct? Perhaps it could be moved to src/ somehow to not interfere with the native extension module?

@ArniDagur
Copy link
Owner

ArniDagur commented Dec 22, 2020

Can you reproduce this behaviour with (run in root of git repository):

#!/bin/sh
set -xe
python3.9 -m pip uninstall -y adblock
maturin build --release --interpreter python3.9
python3.9 -m pip install --user target/wheels/adblock-0.4.0-cp39-*.whl
python3.9 -c "import adblock; print('success! version:', adblock.__version__)"

I can't, unfortunately.

It looks like that adblock module is only required for type annotations?

That's right. It's the most straightforward way I found to make a PEP 561 compatible package.

Is the __init__.py really required, and is the import even correct?

I'm not sure, but it is the pattern that a number of PyO3 examples seem to follow. See for example:

@ArniDagur
Copy link
Owner

I think this is fixed in dc33223

@b3n
Copy link

b3n commented Mar 14, 2021

I have the same issue, and dc33223 did not fix it for me.

@ddevault
Copy link

ddevault commented Apr 7, 2021

I'm seeing this on the package installed system-wide via setup.py

@ArniDagur
Copy link
Owner

ArniDagur commented Apr 7, 2021

@b3n @ddevault Ah, I had been trying to reproduce this when installing with --user. I can reproduce when:

  1. I install the package system-wide
  2. Current working directory is the python-adblock git repository.
  3. I run python3 -c "import adblock"

When I leave the git repository, import adblock works again. Does this match your experience, or does it also happen outside of the git repo?

@ddevault
Copy link

ddevault commented Apr 7, 2021

I've never tried it from the git repository, and that's not how I would use it anyway - I am packaging this for Alpine Linux.

@omnivagant
Copy link

This seemed to surface for Alpine when we went from python 3.8 to 3.9...

@steils
Copy link

steils commented Jun 21, 2021

+1
inside the git directory:

$ python3 -c "import adblock"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/stefan/projects/python-adblock/adblock/__init__.py", line 1, in <module>
    from adblock.adblock import __version__, Engine, FilterSet, BlockerResult, UrlSpecificResources
ModuleNotFoundError: No module named 'adblock.adblock'

There is no abi3.so inside the adblock/ directory even after the build... (maybe it's not supposed to be there, I don't know)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants