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

psycopg/psycopg2 DLL import issues #6734

Open
AgainPsychoX opened this issue Nov 28, 2024 · 6 comments
Open

psycopg/psycopg2 DLL import issues #6734

AgainPsychoX opened this issue Nov 28, 2024 · 6 comments

Comments

@AgainPsychoX
Copy link

Describe the bug
Trying to start the label-studio just crashes...

To Reproduce
Steps to reproduce the behavior:

  1. Enter venv
  2. Install pip install label-studio
  3. Try use label-studio (anything)

Expected behavior
It should just work ;)

Environment:

  • OS: Windows 10
  • Label Studio Version: 1.14.0.post0
  • Python version: 3.13.0

Additional context
Log:

=> Database and media directory: C:\Users\PsychoX\AppData\Local\label-studio\label-studio
=> Static URL is set to: /static/
=> Database and media directory: C:\Users\PsychoX\AppData\Local\label-studio\label-studio
=> Static URL is set to: /static/
Read environment variables from: C:\Users\PsychoX\AppData\Local\label-studio\label-studio
\.env
get 'SECRET_KEY' casted as '<class 'str'>' with default ''
Starting new HTTPS connection (1): o227124.ingest.sentry.io:443
Traceback (most recent call last):
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\django\db\backends\pos
tgresql\psycopg_any.py", line 5, in <module>
    from psycopg import ClientCursor, IsolationLevel, adapt, adapters, errors, sql
ModuleNotFoundError: No module named 'psycopg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\Projects\+embedded\YellowToyCar\.venv\Scripts\label-studio.exe\__main__.py", l
ine 7, in <module>
    sys.exit(main())
             ~~~~^^
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\label_studio\server.py
", line 296, in main
    _setup_env()
    ~~~~~~~~~~^^
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\label_studio\server.py
", line 35, in _setup_env
    get_wsgi_application()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\django\core\wsgi.py",
line 12, in get_wsgi_application
    django.setup(set_prefix=False)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\django\__init__.py", l
ine 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
                      ^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\django\conf\__init__.p
y", line 102, in __getattr__
    self._setup(name)
    ~~~~~~~~~~~^^^^^^
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\django\conf\__init__.p
y", line 89, in _setup
    self._wrapped = Settings(settings_module)
                    ~~~~~~~~^^^^^^^^^^^^^^^^^
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\django\conf\__init__.p
y", line 217, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "F:\Python313\Lib\importlib\__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1022, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\label_studio\core\sett
ings\label_studio.py", line 49, in <module>
    from label_studio.core.utils.common import collect_versions
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\label_studio\core\util
s\common.py", line 28, in <module>
    from django.contrib.postgres.operations import BtreeGinExtension, TrigramExtension
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\django\contrib\postgre
s\operations.py", line 1, in <module>
    from django.contrib.postgres.signals import (
    ...<3 lines>...
    )
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\django\contrib\postgre
s\signals.py", line 5, in <module>
    from django.db.backends.postgresql.psycopg_any import is_psycopg3
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\django\db\backends\pos
tgresql\psycopg_any.py", line 77, in <module>
    from psycopg2 import errors, extensions, sql  # NOQA
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\Projects\+embedded\YellowToyCar\.venv\Lib\site-packages\psycopg2\__init__.py",
 line 51, in <module>
    from psycopg2._psycopg import (                     # noqa
    ...<10 lines>...
    )
ImportError: DLL load failed while importing _psycopg: Nie można odnaleźć określonego mod
ułu.
Sentry is attempting to send 2 pending events
Waiting up to 2 seconds
Press Ctrl-Break to quit
https://o227124.ingest.sentry.io:443 "POST /api/5820521/envelope/ HTTP/1.1" 200 41
@UzitheI
Copy link

UzitheI commented Nov 30, 2024

This bug is not reproducing in mac sonoma 14.5. This must be a compiling issue with psycopg2 as psycopg2 requires a C compiler to build from source. psycopg2-binary has precompiled binaries so replacing this in requirements should do the job. This could also occur if you dont have the right build environment, like not having gcc.

@heidi-humansignal
Copy link
Collaborator

Hello,

Yes, I wasn't able to reproduce it either. Have you tried UzitheI suggestion?

Thank you,
Abu

Comment by Abubakar Saad
Workflow Run

@farioas
Copy link
Member

farioas commented Dec 2, 2024

https://github.com/HumanSignal/label-studio/blob/develop/pyproject.toml#L180
psycopg2-binary is still there.

I was unable to reproduce the issue on 3.12, but there is another issue with numpy for 3.13, which requires gcc to compile modules.

@AgainPsychoX
Copy link
Author

AgainPsychoX commented Dec 7, 2024

Tried installing psycopg2-binary, but it says "Requirement already satisfied".

I also tried on other system, Windows 10, installed Python 3.13, then tried to install pip install label-studio. Then realized Visual Studio Community (with Python stuff) is required for installing numpy and other stuff. Then installed PostgreSQL, because apparently it's not optional despite it says SQLite is also an option... Then I got it all installed, but the same issue as the above, with psycopg2.

Tried installing psycopg2 (not -binary), the same issue. Then somewhere online I found pip install "psycopg[binary]" and it finally worked for me - doesn't mean this issue should be closed, it should be addressed at the very least by documentation, or by fixing the requirements or some install/build scripts.

@UzitheI
Copy link

UzitheI commented Dec 7, 2024

Agreed @AgainPsychoX. psycopg[binary] apparently doesnt build from the source and explicitly specifies the binary wheel. I still believe you're facing this issue because you dont have the right build environment (possibly your C compiler isnt being used or doesnt exist) but there should be build script for environments lacking that.A script for 'if psycopg2 build fails, automatically try for pip install psycopg[binary]' could do the job. @heidi-humansignal

@heidi-humansignal
Copy link
Collaborator

Hello,

Just want to follow up on this. The issue is with psycopg2, its not really compatible with python 3.13 on windows and it cause issues. Downgrading to python 3.12 will solve this problem. We will investigate this further and see what could be possible solutions for it.

Thank you,
Abu

Comment by Abubakar Saad
Workflow Run

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

No branches or pull requests

4 participants