我正在制作一个从网站发送任务的电报机器人https://phys-ege.sdamgia.ru/您需要发送图像。
据我了解,您需要将 svg 转换为 png 或 jpeg,但是在使用 pyvips 库时会出现错误
Traceback (most recent call last):
File "D:/Питончик/hbntdfg.py", line 1, in <module>
import pyvips
File "C:\Users\denve\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvips\__init__.py", line 70, in <module>
gobject_lib = ffi.dlopen(_gobject_libname)
File "C:\Users\denve\AppData\Local\Programs\Python\Python311\Lib\site-packages\cffi\api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Users\denve\AppData\Local\Programs\Python\Python311\Lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Users\denve\AppData\Local\Programs\Python\Python311\Lib\site-packages\cffi\api.py", line 828, in _load_backend_lib
return backend.load_library(path, flags)
OSError: cannot load library 'C:\Program Files (x86)\GTK2-Runtime\bin\libgobject-2.0-0.dll': error 0xc1
我认为您看到了 DLL 冲突。
pyvips 正在尝试打开
libgobject-2.0-0.dll
并且正在查找您在 C:\Program Files (x86)\GTK2-Runtime
中的那个。这可能很旧,无法与 libvips 一起使用,它需要相当新的 libgobject
。
看看win安装说明:
https://github.com/libvips/pyvips#windows-install
并确保遵循 python 3.8 及更高版本的说明。
x=1
r=random.randint(1,69)
url = 'https://phys-ege.sdamgia.ru/test?theme=403&print=true'
response = requests.get(url)
soup = BS(response.content, "html.parser")
data = soup.find_all('div', class_="nobreak")
data_2 = soup.find_all('div', style= "clear:both;display:none")
for i in data:
v = i.find('p',class_= "left_margin")
if x == r:
try:
z = v.find('img').get('src')
svg2png(url='https://ege.sdamgia.ru'+ z,write_to='task.png')
photo = open("D:/Питончик/task.png","rb")
bot.send_photo(chat_id=message.chat.id, photo=photo)
except AttributeError:
print('No photo')
bot.send_message(message.chat.id,v.text)