Почему subprocess.Open не может найти этот исполняемый файл (phantomjs)Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Почему subprocess.Open не может найти этот исполняемый файл (phantomjs)

Сообщение Anonymous »

[обновление]
Я думаю, что сообщение об ошибке на самом деле вводит в заблуждение. Оказывается, если я попытаюсь запустить команду phantomjs, то получаю ошибку:
-bash: /usr/bin/phantomjs: cannot execute: required file not found
Я думаю, что это проблема с исполняемым файлом, а не в том, что Popen не может его найти.
Я пытаюсь используйте selenium.webdriver.PhantomJS на Raspberry Pi 5. Этот простой скрипт
from selenium import webdriver

wd = webdriver.PhantomJS()

ошибка с этим сообщением:
Traceback (most recent call last):
File "/home/jkitchin/.venv/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'phantomjs'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/jkitchin/bots/bibtex/pgs.py", line 3, in
wd = webdriver.PhantomJS()
^^^^^^^^^^^^^^^^^^^^^
File "/home/jkitchin/.venv/lib/python3.11/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__
self.service.start()
File "/home/jkitchin/.venv/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 79, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH.

Однако phantomjs определенно на моем пути:
$ which phantomjs
/usr/bin/phantomjs

С этими разрешениями:
-rwxr-xr-x 1 root root 50179436 Oct 20 13:11 /usr/bin/phantomjs

Я прекрасно могу запустить команду в оболочке.
Этот более простой сценарий также не работает:
import subprocess as sp
sp.run('phantomjs', capture_output=True)

Даже использование полного пути приводит к
Traceback (most recent call last):
File "/home/jkitchin/bots/bibtex/pgs.py", line 5, in
sp.run('/usr/bin/phantomjs', capture_output=True)
File "/usr/lib/python3.11/subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/phantomjs'

Есть идеи, что здесь не так?
[обновление]
Эта программа на Python:
import subprocess as sp
p = sp.run(['ls', '/usr/bin'], capture_output=True)
print('phantomjs' in p.stdout.decode('ascii'))

sp.run(['which', 'phantomjs'])
print()
sp.run(['file', '/usr/bin/phantomjs'])
print()
sp.run(['ls', '-al', '/usr/bin/phantomjs'])
print()
sp.run(['/usr/bin/phantomjs'])

Выдает следующий результат:
True
/usr/bin/phantomjs

/usr/bin/phantomjs: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=93e423f5359137d6cbb97c5e11aa34945e86e004, not stripped

-rwxr-xr-x 1 root root 50179436 Oct 20 13:11 /usr/bin/phantomjs

Traceback (most recent call last):
File "/home/jkitchin/bots/bibtex/pgs.py", line 14, in
sp.run(['/usr/bin/phantomjs'])
File "/usr/lib/python3.11/subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/phantomjs'


Подробнее здесь: https://stackoverflow.com/questions/791 ... -phantomjs
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»