実現したいこと
Python3でモジュールをインポートしたい
前提
前スレッド
https://teratail.com/questions/irgq73vifgeyue
の続きです。
また最大文字数を超えて追記できなくなったので、新しくスレッドを立てました。
試したこと
追記 2023.07.26 19:05
とりあえず、Python3.7のインストール前にスナップショットで遡って、アドバイスを元に再度インストールからやり直しました。
pip3は、Python3.7に付随しているようで、インストールし直したら自動的に入っていました。
その後、cgiを有効に設定し、webブラウザで走るようにしました。
そして、「requests」をインストールしようとしましたが、どういうわけかsudo
ではpython3が見つからないようです。
そこで、su -
でrootになって同様にコマンドを実行すると、「requests」がインストールできました。
この時点で/usr/local/lib/python3.7/site-packages/requests
フォルダーは存在し、中身もあります。
/home/apple2c/.local
フォルダーにはshare
しかありません。
ですが、まだ意図通りにwebブラウザに表示されません。
CentOS7の端末
[apple2c@localhost ~]$ sudo python3 -m pip install requests sudo: python3: コマンドが見つかりません [apple2c@localhost ~]$ su - パスワード: 最終ログイン: 2023/07/26 (水) 18:43:51 JST日時 pts/0 [root@localhost ~]# python3 -m pip install requests Collecting requests Obtaining dependency information for requests from https://files.pythonhosted.org/packages/70/8e/0e2d847013cb52cd35b38c009bb167a1a26b2ce6cd6965bf26b47bc0bf44/requests-2.31.0-py3-none-any.whl.metadata Downloading requests-2.31.0-py3-none-any.whl.metadata (4.6 kB) Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.7/site-packages (from requests) (3.2.0) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests) (3.4) Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.7/site-packages (from requests) (2.0.4) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests) (2023.7.22) Using cached requests-2.31.0-py3-none-any.whl (62 kB) Installing collected packages: requests Successfully installed requests-2.31.0 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@localhost ~]#
test001.py
python3
1#!/usr/local/bin/python3.7 2# coding:utf-8 3 4import sys 5import pprint 6 7print('Content-Type: text/html\n\n') 8print('Status: 200 OK<br>') 9 10pprint.pprint(sys.path) 11print('<br>') 12 13sys.path.append('/usr/local/bin/python3.7/site-packages') 14pprint.pprint(sys.path) 15print('<br>') 16 17import requests # conda install requests 18print('requestsをimportできました')
Macのwebブラウザ
Status: 200 OK ['/var/www/html', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages'] ['/var/www/html', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages', '/usr/local/bin/python3.7/site-packages']
/var/log/httpd/error_log
[Wed Jul 26 18:28:24.720611 2023] [cgi:error] [pid 1630] [client 192.168.1.97:49378] AH01215: Traceback (most recent call last): [Wed Jul 26 18:28:24.720673 2023] [cgi:error] [pid 1630] [client 192.168.1.97:49378] AH01215: File "/var/www/html/test001.py", line 17, in <module> [Wed Jul 26 18:28:24.720708 2023] [cgi:error] [pid 1630] [client 192.168.1.97:49378] AH01215: import requests # conda install requests [Wed Jul 26 18:28:24.720762 2023] [cgi:error] [pid 1630] [client 192.168.1.97:49378] AH01215: File "/usr/local/lib/python3.7/site-packages/requests/__init__.py", line 43, in <module> [Wed Jul 26 18:28:24.720775 2023] [cgi:error] [pid 1630] [client 192.168.1.97:49378] AH01215: import urllib3 [Wed Jul 26 18:28:24.720829 2023] [cgi:error] [pid 1630] [client 192.168.1.97:49378] AH01215: File "/usr/local/lib/python3.7/site-packages/urllib3/__init__.py", line 42, in <module> [Wed Jul 26 18:28:24.720865 2023] [cgi:error] [pid 1630] [client 192.168.1.97:49378] AH01215: "urllib3 v2.0 only supports OpenSSL 1.1.1+, currently " [Wed Jul 26 18:28:24.720975 2023] [cgi:error] [pid 1630] [client 192.168.1.97:49378] AH01215: ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips 26 Jan 2017'. See: https://github.com/urllib3/urllib3/issues/2168
となっていますが、これはrequests
がurllib3
に依存していて、それが入っていないという事でしょうか?
それと、python3 -m pip install requests
とpip3 install requests
の違いが今ひとつ分かっていないのですが、前者は「requests」の依存関係もまとめてインストール、後者は依存関係はインストールされない?という事でしょうか?

回答2件
あなたの回答
tips
プレビュー