Pro.py and python3

Hi all,

we are using seafile pro 7.1.7 on debian 10 and we see some python3 related issues with pro.py, e.g.

sudo -u seafile ./pro.py ldapsync
/usr/bin/python: No module named parse

or

sudo -u seafile ./pro.py search --update
Updating search index, this may take a while...
/usr/bin/python: No module named queue

on debian 10, /usr/bin/python is a symlink to python2, so it is no surprise that this does not work.

there are several places where /usr/bin/python is called:

python/seafevents/office_converter/unoconv.py:#!/usr/bin/env python
python/seafevents/main.py:#!/usr/bin/env python
python/seafevents/virus_scanner/run_virus_scan.py:#!/usr/bin/env python
python/seafevents/ldap_syncer/run_ldap_sync.py:#!/usr/bin/env python
python/seafevents/content_scanner/main.py:#!/usr/bin/env python
python/seafevents/background_tasks.py:#!/usr/bin/env python
python/pyes/managers.py:#!/usr/bin/env python
python/pyes/contrib/mappings.py:#!/usr/bin/env python
python/pyes/contrib/__init__.py:#!/usr/bin/env python
python/pyes/orm/queryset.py:#!/usr/bin/env python
python/pyes/models.py:#!/usr/bin/env python
python/pyes/queryset.py:#!/usr/bin/env python
python/pyes/decorators.py:#!/usr/bin/env python
python/pyes/utils/imports.py:#!/usr/bin/env python
python/pyes/utils/compat.py:#!/usr/bin/env python
python/pyes/pyesthrift/simple_test.py:#!/usr/bin/env python
python/seafes/tests/integration/data/markdown_with_html.txt:#!/usr/bin/env python
python/bin/launch_instance:CLOUD_INIT_SCRIPT = """#!/usr/bin/env python
python/boto/services/result.py:#!/usr/bin/env python
python/boto/services/bs.py:#!/usr/bin/env python
python/boto/pyami/launch_ami.py:#!/usr/bin/env python
python/boto/pyami/installers/ubuntu/ebs.py:BackupScriptTemplate = """#!/usr/bin/env python
python/boto/pyami/installers/ubuntu/ebs.py:BackupCleanupScript= """#!/usr/bin/env python
python/boto/pyami/installers/ubuntu/ebs.py:TagBasedBackupCleanupScript= """#!/usr/bin/env python

I guess these should all be changed to “/usr/bin/env python3”.

Best,
Hp

Hello,
Same configuration (Seafile 7.1.7 / Debian10), same problem.

This is a bug in pro.py script. You can change line 291 to python3.7. This is a workaround. We’ll fix the script in the next version.

Hello,
After apply modification in pro.py, we have still an error :

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/opt/seafile/seafile-server-latest/pro/python/seafevents/ldap_syncer/run_ldap_sync.py", line 7, in <module>
    from ldap import SCOPE_SUBTREE
ModuleNotFoundError: No module named 'ldap'

You should install python3-ldap manually, as stated in the upgrade notes: https://download.seafile.com/published/seafile-manual/upgrade/upgrade_notes_for_7.1.x.md

@Jonathan, I did, and it’s still an issue;

root@seafile1:/srv/seafile/seafile-server-latest# ./pro/pro.py ldapsync --test
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/srv/seafile/seafile-pro-server-7.1.7/pro/python/seafevents/ldap_syncer/run_ldap_sync.py", line 7, in <module>
    from ldap import SCOPE_SUBTREE
ModuleNotFoundError: No module named 'ldap'
root@seafile1:/srv/seafile/seafile-server-latest# pip3 list | grep ldap
python3-ldap           0.9.8.4

Also worth mentioning that python3-ldap has changed name to ldap3, as per description here.

The issue is still present;

root@seafile1:/srv/seafile/seafile-server-latest# ./pro/pro.py ldapsync --test
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/srv/seafile/seafile-pro-server-7.1.7/pro/python/seafevents/ldap_syncer/run_ldap_sync.py", line 7, in <module>
    from ldap import SCOPE_SUBTREE
ModuleNotFoundError: No module named 'ldap'
root@seafile1:/srv/seafile/seafile-server-latest# pip3 list | grep ldap
ldap3                  2.8.1
python3-ldap           0.9.8.4

Can you import ldap module manually from a python3 promt?

No, because ldap is not the module name for ldap3 (or python3-ldap). The module name is ldap3, and it seems it’s been like that for a while.

root@seafile1:/srv/seafile/seafile-server-latest# /usr/bin/python3 --version
Python 3.7.3
root@seafile1:/srv/seafile/seafile-server-latest# pip3 --version
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
root@seafile1:/srv/seafile/seafile-server-latest# /usr/bin/pip3 list|grep ldap
ldap3                  2.8.1
python3-ldap           0.9.8.4
root@seafile1:/srv/seafile/seafile-server-latest# pip3 show ldap3
Name: ldap3
Version: 2.8.1
Summary: A strictly RFC 4510 conforming LDAP V3 pure Python client library
Home-page: https://github.com/cannatag/ldap3
Author: Giovanni Cannata
Author-email: cannatag@gmail.com
License: LGPL v3
Location: /usr/local/lib/python3.7/dist-packages
Requires: pyasn1
Required-by:
root@seafile1:/srv/seafile/seafile-server-latest# pip3 show python3-ldap
Name: python3-ldap
Version: 0.9.8.4
Summary: A strictly RFC 4511 conforming LDAP V3 pure Python client. Same codebase for Python 2, Python3, PyPy and PyPy 3
Home-page: https://github.com/cannatag/ldap3
Author: Giovanni Cannata
Author-email: cannatag@gmail.com
License: LGPL v3
Location: /usr/local/lib/python3.7/dist-packages
Requires: pyasn1
Required-by:
root@seafile1:/srv/seafile/seafile-server-latest# python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ldap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ldap'
>>> import ldap3
>>> quit()
root@seafile1:/srv/seafile/seafile-server-latest#

The current code is only compatible with ldap library instead of the new name “ldap3”. You can still use pip to install python-ldap library for python 3.7.