https://co.bsnws.net/article/287
こちらのサイトを参考にrequests-htmlを追加しようとしましたが
C:\Users\sasak\python_edit>script.py
Traceback (most recent call last):
File "C:\Users\sasak\python_edit\script.py", line 1, in <module>
from requests_html import session # requests_htmlの読み込み
ModuleNotFoundError: No module named 'requests_html'
とモジュールがないと言われます。
同じディレクト内で pip install requests-html
と呼び出しても既にあると言われます
どうすれば実行できるようになるでしょうか?
お優しい方助けてください。。。
Requirement already satisfied: requests-html in d:\lib\site-packages (0.10.0)
Requirement already satisfied: w3lib in d:\lib\site-packages (from requests-html) (1.22.0)
Requirement already satisfied: bs4 in d:\lib\site-packages (from requests-html) (0.0.1)
Requirement already satisfied: pyquery in d:\lib\site-packages (from requests-html) (1.4.3)
Requirement already satisfied: requests in d:\lib\site-packages (from requests-html) (2.25.1)
Requirement already satisfied: fake-useragent in d:\lib\site-packages (from requests-html) (0.1.11)
Requirement already satisfied: pyppeteer>=0.0.14 in d:\lib\site-packages (from requests-html) (0.2.5)
Requirement already satisfied: parse in d:\lib\site-packages (from requests-html) (1.19.0)
Requirement already satisfied: appdirs<2.0.0,>=1.4.3 in d:\lib\site-packages (from pyppeteer>=0.0.14->requests-html) (1.4.4)
Requirement already satisfied: pyee<9.0.0,>=8.1.0 in d:\lib\site-packages (from pyppeteer>=0.0.14->requests-html) (8.1.0)
Requirement already satisfied: tqdm<5.0.0,>=4.42.1 in d:\lib\site-packages (from pyppeteer>=0.0.14->requests-html) (4.59.0)
Requirement already satisfied: websockets<9.0,>=8.1 in d:\lib\site-packages (from pyppeteer>=0.0.14->requests-html) (8.1)
Requirement already satisfied: urllib3<2.0.0,>=1.25.8 in d:\lib\site-packages (from pyppeteer>=0.0.14->requests-html) (1.26.3)
Requirement already satisfied: beautifulsoup4 in d:\lib\site-packages (from bs4->requests-html) (4.9.3)
Requirement already satisfied: soupsieve>1.2 in d:\lib\site-packages (from beautifulsoup4->bs4->requests-html) (2.2)
Requirement already satisfied: cssselect>0.7.9 in d:\lib\site-packages (from pyquery->requests-html) (1.1.0)
Requirement already satisfied: lxml>=2.1 in d:\lib\site-packages (from pyquery->requests-html) (4.6.2)
Requirement already satisfied: chardet<5,>=3.0.2 in d:\lib\site-packages (from requests->requests-html) (4.0.0)
Requirement already satisfied: certifi>=2017.4.17 in d:\lib\site-packages (from requests->requests-html) (2020.12.5)
Requirement already satisfied: idna<3,>=2.5 in d:\lib\site-packages (from requests->requests-html) (2.10)
Requirement already satisfied: six>=1.4.1 in d:\lib\site-packages (from w3lib->requests-html) (1.15.0)
ソースコードはこちらです
python
1 2from requests_html import session # requests_htmlの読み込み 3 4# ターゲットなるURL 5url = 'http://co.bsnws.net/article/269' 6# ページに接続 7response = session.get(url) 8# 取得したオブジェクトをhtmlに変換 9article = response.html 10# ページをtextに変換 11print(article.text) 12# ページをhtmlタグに変換 13# print(article.html)
バージョン
Python 3.8.5
requests-html 0.10.0
import sys
print(sys.path)
上記のコードを適当な名前のファイル(拡張子.py)で作成し、コマンドプロンプトで実行した結果を教えてください。
C:\Users\sasak\python_edit>test.py
['C:\\Users\\sasak\\python_edit', 'C:\\Users\\sasak\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip', 'C:\\Users\\sasak\\AppData\\Local\\Programs\\Python\\Python39\\DLLs', 'C:\\Users\\sasak\\AppData\\Local\\Programs\\Python\\Python39\\lib', 'C:\\Users\\sasak\\AppData\\Local\\Programs\\Python\\Python39', 'C:\\Users\\sasak\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages']
こちらの結果になりました。
pipのログでは、「d:\lib\site-packages」にhtml-requestsなどが追加されていますが、コマンドラインから「XXXX.py」を直接実行したときには↑の結果のようにそれが使われていません。
↑の結果を見ると、Python 3.8.5のほかに、Python 3.9.xがインストールされているようです。記憶にありませんか?
3.9.xのインストーるの記憶はちょっとわからないですが、もしかしたらしたのかもしれません。。。
コマンドプロンプトで、「where python.exe」を実行し結果の文字列をコピー、「where pip.exe」を実行し同様に結果の文字列をコピー、コメントで報告してください。
where python.exe
ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
D:\python.exe
C:\Users\sasak\Anaconda3\python.exe
C:\Users\sasak\AppData\Local\Programs\Python\Python39\python.exe
C:\Users\sasak\AppData\Local\Microsoft\WindowsApps\python.exe
ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
where pip.exe
ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
D:\Scripts\pip.exe
C:\Users\sasak\AppData\Local\Programs\Python\Python39\Scripts\pip.exe
こちらでよろしいでしょうか?
「where python.exe」で4つ検索されていますが、末尾のひとつだけはWindows付属の「PythonをWindows Storeからダウンロードさせる案内用」アプリです。残りは全部Python本体ですね。
おそらく、DドライブにあるのがPython 3.8.5で、C:\Users\sasak\AppData\Local\Programs\Python\Python39にあるのがPython 3.9.x、ほかにもAnaconda3に付属のPython(バージョン不明)もあります。
なるほど。。。複数のpythonが入り混じってる状態なんですね。。。
回答1件
あなたの回答
tips
プレビュー
