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

Sanic failed to start when installed using PDM #2828

Open
1 task done
pyx opened this issue Sep 25, 2023 · 11 comments
Open
1 task done

Sanic failed to start when installed using PDM #2828

pyx opened this issue Sep 25, 2023 · 11 comments
Labels

Comments

@pyx
Copy link
Contributor

pyx commented Sep 25, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

As mentioned in the the book Python Web Developmentwith Sanic, I installed sanic with pdm:

$ mkdir test-sanic
$ cd test-sanic
$ pdm init
... with all default settings
$ pdm run sanic

It failed with:
ModuleNotFoundError: No module named 'pkg_resources'

Same error within virtual environment created by pdm as:

$ . .venv/bin/activate
[.venv]$ sanic

python version 3.11
sanic version 23.6.0
pdm version 2.9.2

Code snippet

No response

Expected Behavior

Should be able to run sanic CLI, it worked with virtual environment I created manually.

How do you run Sanic?

Sanic CLI

Operating System

Linux

Sanic Version

23.6.0

Additional context

No response

@pyx pyx added the bug label Sep 25, 2023
@sjsadowski
Copy link
Contributor

Confirmed. This appears to be an upstream issue with tracerite

[💻 ssadowski@q|test-sanic]$ pdm run sanic
Traceback (most recent call last):
  File "/playground/test-sanic/.venv/bin/sanic", line 5, in <module>
    from sanic.__main__ import main
  File "/playground/test-sanic/.venv/lib/python3.11/site-packages/sanic/__init__.py", line 6, in <module>
    from sanic.app import Sanic
  File "/playground/test-sanic/.venv/lib/python3.11/site-packages/sanic/app.py", line 55, in <module>
    from sanic.application.state import ApplicationState, ServerStage
  File "/playground/test-sanic/.venv/lib/python3.11/site-packages/sanic/application/state.py", line 13, in <module>
    from sanic.server.async_server import AsyncioServer
  File "/playground/test-sanic/.venv/lib/python3.11/site-packages/sanic/server/__init__.py", line 5, in <module>
    from sanic.server.runners import serve
  File "/playground/test-sanic/.venv/lib/python3.11/site-packages/sanic/server/runners.py", line 6, in <module>
    from sanic.config import Config
  File "/playground/test-sanic/.venv/lib/python3.11/site-packages/sanic/config.py", line 13, in <module>
    from sanic.errorpages import DEFAULT_FORMAT, check_error_format
  File "/playground/test-sanic/.venv/lib/python3.11/site-packages/sanic/errorpages.py", line 26, in <module>
    from sanic.pages.error import ErrorPage
  File "/playground/test-sanic/.venv/lib/python3.11/site-packages/sanic/pages/error.py", line 3, in <module>
    import tracerite.html
  File "/playground/test-sanic/.venv/lib/python3.11/site-packages/tracerite/__init__.py", line 1, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

Tagging in @Tronic and it may make sense to open a correlating issue there.

@Tronic
Copy link
Member

Tronic commented Sep 26, 2023

Looks like it is missing setuptools (where that module comes from). Normally Python comes with that installed, but in virtual envs it is apparently not available. Can you try pip install setuptools manually within PDM virtual env and report back?

If that fixes it, we are just missing that dependency in tracerite.

@sjsadowski
Copy link
Contributor

I added setuptools and it failed without error (correctly, I might add, because there's nothing for it to actually run yet) so I'd say that seems to be accurate. I'll create a quick stub for sanic after work and verify.

@pyx
Copy link
Contributor Author

pyx commented Sep 26, 2023

Looks like it is missing setuptools (where that module comes from). Normally Python comes with that installed, but in virtual envs it is apparently not available. Can you try pip install setuptools manually within PDM virtual env and report back?

If that fixes it, we are just missing that dependency in tracerite.

Yes, you are correct. After pdm add setuptools, it works fine.

@Tronic
Copy link
Member

Tronic commented Sep 26, 2023

Fixed (not tested) on Tracerite git now. Needs a new tracerite release, @ahopkins can you push one out?

@pyx
Copy link
Contributor Author

pyx commented Oct 3, 2023

@Tronic
I am trying to revitalize some of my sanic plugin projects, and found this, it mentioned Tracerite, seems to be related, you might find it interesting.

$ pdm run pytest tests/
============================= test session starts =============================
platform linux -- Python 3.11.5, pytest-7.4.2, pluggy-1.2.0
rootdir: /home/pyx/projects/sanic-wtf
plugins: anyio-3.7.1, cov-4.1.0
collected 12 items                                                            

tests/test_form.py ........                                             [ 66%]
tests/test_utils.py .                                                   [ 75%]
tests/test_validators.py ...                                            [100%]

============================== warnings summary ===============================
.venv/lib/python3.11/site-packages/tracerite/__init__.py:1
  /home/pyx/projects/sanic-wtf/.venv/lib/python3.11/site-packages/tracerite/__init__.py:1: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    import pkg_resources

.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2871
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2871
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2871
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2871
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2871
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2871
  /home/pyx/projects/sanic-wtf/.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2871: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('sphinxcontrib')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(pkg)

.venv/lib/python3.11/site-packages/websockets/connection.py:9
  /home/pyx/projects/sanic-wtf/.venv/lib/python3.11/site-packages/websockets/connection.py:9: DeprecationWarning: websockets.connection was renamed to websockets.protocol and Connection was renamed to Protocol
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

@Tronic
Copy link
Member

Tronic commented Oct 9, 2023

Upcoming tracerite-1.1.1 (git main) no longer uses pkg_resources so this issue is resolved for good. Still needs Tracerite pypi release and then Sanic depending on the new one.

@rmorshea
Copy link

rmorshea commented Dec 8, 2023

Tracerite 1.1.1 still depends on pkg_resources so I still get this error.

@Tronic
Copy link
Member

Tronic commented Dec 11, 2023

Tracerite 1.1.1 still depends on pkg_resources so I still get this error.

Sorry about that. Can you try if the PR solves this issue so we could get that released as another version... sanic-org/tracerite#10

@rayanth
Copy link

rayanth commented Feb 13, 2024

confirmed still an issue with sanic v23.12.1 as of Feb 13, 2024.

installing setuptools to the virtualenv fixed the issue for me.

edit: I was not using PDM, just new virtualenv, pip install sanic, copy the hello world code, and sanic server and got the error, until i added setuptools to the virtualenv.

@bgraceful
Copy link

BTW https://github.com/astral-sh/uv

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

No branches or pull requests

6 participants