0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

import requests できない

Last updated at Posted at 2020-08-07

起きた問題


(venv)$  python main.py

Traceback (most recent call last):
  File "main.py", line 3, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

環境

  • WSL2
  • Ubuntu18.04
  • Python3.8

パスの確認

Pythonモジュールのimportができなくなったときの対処記録に従ってPathの追加までやってみる。

pythonが探索するパス


>>> import sys
>>> sys.path
['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/USERNAME/documents/manzai/venv/lib/python3.8/site-packages']

requests

(venv)$ pip show requests

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Name: requests
Version: 2.24.0
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: /usr/local/lib/python3.8/dist-packages
Requires: chardet, idna, urllib3, certifi
Required-by: httpie

/usr/local/lib/python3.8/dist-packagesにインストールされている。
このディレクトリはPythonの探索範囲に入っていないのでPathを追加。


>>> sys.path.append('/usr/local/lib/python3.8/dist-packages')

>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/requests/__init__.py", line 43, in <module>
    import urllib3
ModuleNotFoundError: No module named 'urllib3'

今度はurllib3がないと言われた。

解決


$ sudo pip install requests -t /usr/lib/python3.8

/usr/lib/python3.8 にrequestsをインストールで行けた!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?