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

[Bug]: 在 python 3.12 下无法运行 #41

Closed
4 tasks done
BA7JCM opened this issue Jan 5, 2023 · 1 comment
Closed
4 tasks done

[Bug]: 在 python 3.12 下无法运行 #41

BA7JCM opened this issue Jan 5, 2023 · 1 comment

Comments

@BA7JCM
Copy link

BA7JCM commented Jan 5, 2023

请确保您已阅读以上注意事项,并勾选下方的确认框。

  • 我已经使用一个干净且无其它非必要的插件的环境测试过,问题依旧存在。
  • 我已经在 Issue Tracker 中找过我要提出的问题,没有找到相同问题的ISSUE。
  • 我已知晓并同意,此处仅用于汇报程序中存在的问题。若这个 Issue 是关于其他非程序本身问题,则我的 Issue 可能会被无条件自动关闭或/并锁定。
  • 我已知晓并同意,如果我不按照模板提供的指示进行填写,则我的 Issue 可能会被无条件删除。

PagerMaid 版本 (或 Commit Id)

0a4dda0

运行环境

Ubuntu

运行架构

AMD64

重现步骤

从python官网下载python12(https://www.python.org/ftp/python/3.12.0/Python-3.12.0a3.tar.xz )的源码,通过以下命令编译安装python

apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev -y
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0a3.tar.xz
tar -xf Python-3.12.0a3.tar.xz 
cd Python-3.12.0a3/
./configure && make && make install

然后手动安装PagerMaid-Pyro并运行

git clone https://github.com/TeamPGM/PagerMaid-Pyro
cd PagerMaid-Pyro/
# 修改配置文件过程省略
pip3.12 install -Ur requirements.txt 
python3.12 -m pagermaid

无法运行,得到以下报错:

Traceback (most recent call last):
  File "<frozen runpy>", line 189, in _run_module_as_main
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "/root/PagerMaid-Pyro/test/PagerMaid-Pyro/pagermaid/__init__.py", line 5, in <module>
    import pyrogram.types
  File "/usr/local/lib/python3.12/site-packages/pyrogram/__init__.py", line 40, in <module>
    from .sync import idle, compose
  File "/usr/local/lib/python3.12/site-packages/pyrogram/sync.py", line 99, in <module>
    wrap(Methods)
  File "/usr/local/lib/python3.12/site-packages/pyrogram/sync.py", line 95, in wrap
    async_to_sync(source, name)
  File "/usr/local/lib/python3.12/site-packages/pyrogram/sync.py", line 31, in async_to_sync
    main_loop = asyncio.get_event_loop()
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/events.py", line 676, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'MainThread'.

系统是Debian11,之所以上面选Ubuntu是因为Ubuntu是基于Debian的,是选项中最接近我的运行环境的一个

期望的结果是什么?

程序正常启动,就像这样:

INFO [2023-01-06 00:12:06] [apscheduler.scheduler] Scheduler started
INFO [2023-01-06 00:12:06] [casbin.model.assertion] Role links for: g
INFO [2023-01-06 00:12:06] [casbin.rbac.default_role_manager.role_manager] owner < admin, admin < builder, builder < default
INFO [2023-01-06 00:12:06] [pagermaid] 加载内置模块: account, avoid, backup, clock, help, message, mixpanel, plugin, prune, reload, sentry, status, sudo, system, update
DEBUG [2023-01-06 00:12:06] [apscheduler.scheduler] Looking for jobs to run
DEBUG [2023-01-06 00:12:06] [apscheduler.scheduler] No jobs; waiting until a job is added
INFO [2023-01-06 00:12:06] [pagermaid] 将平台检测为“linux”,进入PagerMaid的早期加载过程。
Welcome to Pyrogram (version 2.0.93)
Pyrogram is free software and comes with ABSOLUTELY NO WARRANTY. Licensed
under the terms of the GNU Lesser General Public License v3.0 (LGPL-3.0).

Enter phone number or bot token: 

实际的结果是什么?

在python3.11下可正常运行,但在python3.12下就无法运行

简单的复现代码/链接(可选)

apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev -y
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0a3.tar.xz
tar -xf Python-3.12.0a3.tar.xz 
cd Python-3.12.0a3/
./configure && make && make install
cd ..
git clone https://github.com/TeamPGM/PagerMaid-Pyro
cd PagerMaid-Pyro/
# 修改配置文件过程省略
pip3.12 install -Ur requirements.txt 
python3.12 -m pagermaid

日志记录(可选)

root@leaf:~/PagerMaid-Pyro/test/PagerMaid-Pyro# pip3.12 install -Ur requirements.txt 
Requirement already satisfied: pyrogram==2.0.93 in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 1)) (2.0.93)
Requirement already satisfied: TgCrypto==1.2.5 in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 2)) (1.2.5)
Requirement already satisfied: Pillow>=8.4.0 in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 3)) (9.4.0)
Requirement already satisfied: pytz>=2021.3 in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 4)) (2022.7)
Requirement already satisfied: PyYAML>=6.0 in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 5)) (6.0)
Requirement already satisfied: coloredlogs>=15.0.1 in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 6)) (15.0.1)
Requirement already satisfied: psutil>=5.8.0 in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 7)) (5.9.4)
Requirement already satisfied: httpx in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 8)) (0.23.3)
Requirement already satisfied: apscheduler in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 9)) (3.9.1.post1)
Requirement already satisfied: sqlitedict in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 10)) (2.1.0)
Requirement already satisfied: casbin==1.17.5 in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 11)) (1.17.5)
Requirement already satisfied: sentry-sdk==1.12.1 in /usr/local/lib/python3.12/site-packages (from -r requirements.txt (line 12)) (1.12.1)
Requirement already satisfied: pyaes==1.6.1 in /usr/local/lib/python3.12/site-packages (from pyrogram==2.0.93->-r requirements.txt (line 1)) (1.6.1)
Requirement already satisfied: pysocks==1.7.1 in /usr/local/lib/python3.12/site-packages (from pyrogram==2.0.93->-r requirements.txt (line 1)) (1.7.1)
Requirement already satisfied: simpleeval>=0.9.11 in /usr/local/lib/python3.12/site-packages (from casbin==1.17.5->-r requirements.txt (line 11)) (0.9.12)
Requirement already satisfied: certifi in /usr/local/lib/python3.12/site-packages (from sentry-sdk==1.12.1->-r requirements.txt (line 12)) (2022.12.7)
Requirement already satisfied: urllib3>=1.26.11 in /usr/local/lib/python3.12/site-packages (from sentry-sdk==1.12.1->-r requirements.txt (line 12)) (1.26.13)
Requirement already satisfied: humanfriendly>=9.1 in /usr/local/lib/python3.12/site-packages (from coloredlogs>=15.0.1->-r requirements.txt (line 6)) (10.0)
Requirement already satisfied: httpcore<0.17.0,>=0.15.0 in /usr/local/lib/python3.12/site-packages (from httpx->-r requirements.txt (line 8)) (0.16.3)
Requirement already satisfied: rfc3986[idna2008]<2,>=1.3 in /usr/local/lib/python3.12/site-packages (from httpx->-r requirements.txt (line 8)) (1.5.0)
Requirement already satisfied: sniffio in /usr/local/lib/python3.12/site-packages (from httpx->-r requirements.txt (line 8)) (1.3.0)
Requirement already satisfied: setuptools>=0.7 in /usr/local/lib/python3.12/site-packages (from apscheduler->-r requirements.txt (line 9)) (65.5.0)
Requirement already satisfied: six>=1.4.0 in /usr/local/lib/python3.12/site-packages (from apscheduler->-r requirements.txt (line 9)) (1.16.0)
Requirement already satisfied: tzlocal!=3.*,>=2.0 in /usr/local/lib/python3.12/site-packages (from apscheduler->-r requirements.txt (line 9)) (4.2)
Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.12/site-packages (from httpcore<0.17.0,>=0.15.0->httpx->-r requirements.txt (line 8)) (0.14.0)
Requirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.12/site-packages (from httpcore<0.17.0,>=0.15.0->httpx->-r requirements.txt (line 8)) (3.6.2)
Requirement already satisfied: idna in /usr/local/lib/python3.12/site-packages (from rfc3986[idna2008]<2,>=1.3->httpx->-r requirements.txt (line 8)) (3.4)
Requirement already satisfied: pytz-deprecation-shim in /usr/local/lib/python3.12/site-packages (from tzlocal!=3.*,>=2.0->apscheduler->-r requirements.txt (line 9)) (0.1.0.post0)
Requirement already satisfied: tzdata in /usr/local/lib/python3.12/site-packages (from pytz-deprecation-shim->tzlocal!=3.*,>=2.0->apscheduler->-r requirements.txt (line 9)) (2022.7)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
root@leaf:~/PagerMaid-Pyro/test/PagerMaid-Pyro# python3.12 -m pagermaid
Traceback (most recent call last):
  File "<frozen runpy>", line 189, in _run_module_as_main
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "/root/PagerMaid-Pyro/test/PagerMaid-Pyro/pagermaid/__init__.py", line 5, in <module>
    import pyrogram.types
  File "/usr/local/lib/python3.12/site-packages/pyrogram/__init__.py", line 40, in <module>
    from .sync import idle, compose
  File "/usr/local/lib/python3.12/site-packages/pyrogram/sync.py", line 99, in <module>
    wrap(Methods)
  File "/usr/local/lib/python3.12/site-packages/pyrogram/sync.py", line 95, in wrap
    async_to_sync(source, name)
  File "/usr/local/lib/python3.12/site-packages/pyrogram/sync.py", line 31, in async_to_sync
    main_loop = asyncio.get_event_loop()
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/events.py", line 676, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'MainThread'.
root@leaf:~/PagerMaid-Pyro/test/PagerMaid-Pyro#

补充说明(可选)

No response

@omg-xtao omg-xtao changed the title [Bug]: 在python12下无法运行 [Bug]: 在 python 3.12 下无法运行 Jan 14, 2023
@ricky8955555
Copy link

ricky8955555 commented Jun 12, 2023

这是因为 Python 3.12.0 开始弃用了 get_event_loop() 创建 EventLoop 的形式。

根据 cython/cython#5183 报导:

asyncio.get_event_loop() and many other asyncio functions like ensure_future(), shield() or gather(), and also the get_event_loop() method of BaseDefaultEventLoopPolicy now raise a RuntimeError if called when there is no running event loop and the current event loop was not set. Previously they implicitly created and set a new current event loop. DeprecationWarning is no longer emitted if there is no running event loop but the current event loop is set in the policy. (Contributed by Serhiy Storchaka in python/cpython#93453.)

当时 3.12.0a3 的 API 修改为:一旦在未存在 current_event_loop 的状态下使用 get_event_loop() 将会抛出 RuntimeError 错误加上 DeprecationWarning 警告。

后 Python 意识到兼容性问题,从而根据现 https://docs.python.org/3.12/whatsnew/3.12.html#changes-in-the-python-api 说明:

The get_event_loop() method of the default event loop policy now emits a DeprecationWarning if there is no current event loop set and it decides to create one. (Contributed by Serhiy Storchaka and Guido van Rossum in python/cpython#100160.)

现已将抛出 RuntimeError 错误的策略移除。

而又因为 Pyrogram 的 master 分支上 pyrogram/sync.py#L31 仍在使用过时的方法创建 EventLoop 造成在 3.12.0a3 上运行抛出异常。

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

3 participants