質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

1970閲覧

CentOS8にPythonで作成したプログラムを入れてサーバ上でGoogleCromeを動かしたい

takahiro00

総合スコア84

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/08/04 15:20

前提・実現したいこと

CentOS8にPythonで作成したプログラム(セレニウムを実行する)を入れて
CentOS上で動かしたいのですが、エラーが出てしまいうまく動きません。
CentoOSにはchromedriverなどの必要な物はインストール済です。

発生している問題・エラーメッセージ

[xx@xx py]$ python3.6 test.py Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start stdin=PIPE) File "/usr/lib64/python3.6/subprocess.py", line 729, in __init__ restore_signals, start_new_session) File "/usr/lib64/python3.6/subprocess.py", line 1364, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "test.py", line 44, in <module> driver = webdriver.Chrome(chrome_options=options) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__ self.service.start() File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

該当のソースコード

必要な箇所だけ抜粋してます

Python

1import random 2 3import psycopg2 4import tempfile 5from selenium import webdriver 6from bs4 import BeautifulSoup 7import requests 8import time 9import cv2 10from selenium.webdriver.common.alert import Alert 11from selenium.webdriver.common.action_chains import ActionChains 12from selenium.webdriver.common.action_chains import ActionChains 13from selenium.webdriver.chrome.options import Options 14from selenium.webdriver.support import expected_conditions 15from selenium.webdriver.support.wait import WebDriverWait 16from selenium.webdriver.chrome.options import Options 17from requests.exceptions import Timeout 18 19options = Options() 20options.add_argument('--headless') 21options.add_argument('--no-sandbox') 22options.add_argument('--disable-gpu') 23options.add_argument('--window-size=1280,1024') 24driver = webdriver.Chrome(chrome_options=options)

試したこと

chromedriver-binaryのバージョンをいろいろ試したのですが、変化なしです。

補足情報(FW/ツールのバージョンなど)

chromedriver-binary-75.0.3770.8.0
CentOS8
Python3.6

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

can110

2020/08/10 04:00

> CentoOSにはchromedriverなどの必要な物はインストール済です。 インストールでの実行手順を具体的に記載ください。
guest

回答2

0

自己解決

再インストールしたら直りました。
原因は別のサーバからドライバをコピペしてきたことでした。
お騒がせいたしました。

投稿2020/08/10 13:45

takahiro00

総合スコア84

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'

ですね。
PATHの通ったところに置きましょう。

投稿2020/08/04 15:24

otn

総合スコア84555

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

takahiro00

2020/08/10 03:44 編集

回答ありがとうございます。 options = Options() options.add_argument('--headless') options.add_argument('--no-sandbox') options.add_argument('--disable-gpu') options.add_argument('--window-size=1280,1024') options.binary_location = "/home/xxx/py/chromedriver" driver = webdriver.Chrome(chrome_options=options) のような感じでパスを通したのですが、以下のようなエラーが出てしまいます。。。 Traceback (most recent call last): File "test.py", line 46, in <module> driver = webdriver.Chrome(chrome_options=options) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ desired_capabilities=desired_capabilities) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /home/xxx/py/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.) ちなみに、別のサーバでは最初に記載したソースで正常に動いているのです。 (何か設定をしたような気がしますが、忘れてしまいました。。)
otn

2020/08/10 03:58

そもそもChromeは正常に起動できるのでしょうか?
takahiro00

2020/08/10 04:20

正常に動く方のサーバは [xx@xx py]$ chromedriver Starting ChromeDriver 81.0.4044.69 (6813546031a4bc83f717a2ef7cd4ac6ec1199132-refs/branch-heads/4044@{#776}) on port 9515 Only local connections are allowed. Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code. [1597033032.933][SEVERE]: bind() failed: Cannot assign requested address (99) となるのですが、 動かない方のサーバは [xx@xx py]$ chromedriver -bash: chromedriver: command not found となってしまいます。 ディレクトリ上にchromedriverはあるはずなのですが、何故でしょうか パスが通ってないとかでしょうか。 色々調べたのですが、パスの通し方がわからず、。。
takahiro00

2020/08/10 06:36

chromedriverはインストールし直したら正常にバージョン確認までできましたが、 google-chromeの方がインストールできない状態です。 もう意味不明なので迷宮入りにします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問