Pythonでpipを利用してrequestモジュールをインストールしたら、以下のエラーが出たので解説策を記載していきます。
DistutilsOptionError: must supply either home or prefix/exec-prefix -- not both
■ エラー全文
エラー分を記載します。
# pip install requests -t .
Collecting requests
Using cached https://files.pythonhosted.org/packages/f1/ca/10332a30cb25b627192b4ea272c351bce3ca1091e541245cccbace6051d8/requests-2.20.0-py2.py3-none-any.whl
Collecting idna<2.8,>=2.5 (from requests)
Using cached https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
Using cached https://files.pythonhosted.org/packages/56/9d/1d02dd80bc4cd955f98980f28c5ee2200e1209292d5f9e9cc8d030d18655/certifi-2018.10.15-py2.py3-none-any.whl
Collecting urllib3<1.25,>=1.21.1 (from requests)
Using cached https://files.pythonhosted.org/packages/8c/4b/5cbc4cb46095f369117dcb751821e1bef9dd86a07c968d8757e9204c324c/urllib3-1.24-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Installing collected packages: idna, certifi, urllib3, chardet, requests
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip/_internal/cli/base_command.py", line 143, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip/_internal/commands/install.py", line 366, in run
use_user_site=options.use_user_site,
File "/usr/local/lib/python2.7/site-packages/pip/_internal/req/__init__.py", line 49, in install_given_reqs
**kwargs
File "/usr/local/lib/python2.7/site-packages/pip/_internal/req/req_install.py", line 760, in install
use_user_site=use_user_site, pycompile=pycompile,
File "/usr/local/lib/python2.7/site-packages/pip/_internal/req/req_install.py", line 382, in move_wheel_files
warn_script_location=warn_script_location,
File "/usr/local/lib/python2.7/site-packages/pip/_internal/wheel.py", line 215, in move_wheel_files
prefix=prefix,
File "/usr/local/lib/python2.7/site-packages/pip/_internal/locations.py", line 165, in distutils_scheme
i.finalize_options()
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py", line 264, in finalize_options
"must supply either home or prefix/exec-prefix -- not both"
DistutilsOptionError: must supply either home or prefix/exec-prefix -- not both
■ 解決策
HOMEディレクトリに.pydistutils.cfg
ファイルを作成し、以下を記載するだけです。
[install]
prefix=
■ 作業ログ
// ディレクト作成
# vi ~/.pydistutils.cfg
// 記載
$ cat ~/.pydistutils.cfg
[install]
prefix=
// 再度、インストール
# pip install request -t .
Collecting request
Downloading https://files.pythonhosted.org/packages/b8/13/b88a65f14470f3e17d72a1a930f173b36717c211685dbbadfc2e5ba21303/request-1.0.2.tar.gz
Collecting get (from request)
Downloading https://files.pythonhosted.org/packages/dc/bd/264e65844b66e2b5fa829f3f6c526056ee14a0508fb6b454e0af4105a21c/get-1.0.3.tar.gz
Collecting post (from request)
Downloading https://files.pythonhosted.org/packages/7f/ea/ddf22395dcee7a45b7ab7564a087725cafc778f421268814cd8a5ec9ffdf/post-1.0.2.tar.gz
Collecting setuptools (from request)
Downloading https://files.pythonhosted.org/packages/96/06/c8ee69628191285ddddffb277bd5abdf769166e7a14b867c2a172f0175b1/setuptools-40.4.3-py2.py3-none-any.whl (569kB)
100% |████████████████████████████████| 573kB 3.7MB/s
Collecting query_string (from get->request)
Downloading https://files.pythonhosted.org/packages/be/2d/719132c49c715743afff3781e04489cd21189914a563b56837f891fd02ac/query_string-1.0.2.tar.gz
Collecting public (from query_string->get->request)
Downloading https://files.pythonhosted.org/packages/0e/45/1a8ab7780a60b8dbfd030b3b8d8515f80f4ff5c6a1b39f4fcb956575f421/public-2.0.1-py2.py3-none-any.whl
Building wheels for collected packages: request, get, post, query-string
Running setup.py bdist_wheel for request ... done
Stored in directory: /Users/user_name/Library/Caches/pip/wheels/2d/97/9e/52761f5f62936056448f467ea6e60f13405a4d2c95fd98d141
Running setup.py bdist_wheel for get ... done
Stored in directory: /Users/user_name/Library/Caches/pip/wheels/bf/93/96/706b669b49bb26e647439e1539f151b2b2df889327bcac0c22
Running setup.py bdist_wheel for post ... done
Stored in directory: /Users/user_name/Library/Caches/pip/wheels/0b/43/70/98791de554b42699fef279ec02ad5f9bd088cf6a97bb60bb3e
Running setup.py bdist_wheel for query-string ... done
Stored in directory: /Users/user_name/Library/Caches/pip/wheels/78/2f/5d/0cacc1571db01f715f3173cd906aa21abde2864857397b759f
Successfully built request get post query-string
Installing collected packages: setuptools, public, query-string, get, post, request
Successfully installed get-1.0.3 post-1.0.2 public-2.0.1 query-string-1.0.2 request-1.0.2 setuptools-40.4.3
以上です。
参考