【Python3.8】virtualenvで仮想環境を作ろうとしたらmodule 'platform' has no attribute 'linux_distribution'
279, 2020-01-23
目次
環境
- Ubuntu 16.04.6 LTS (Xenial Xerus)
- Python 3.8.0b4
遭遇したエラー
以下のコマンドで仮想環境venv
を作ろうとした。
:::text
$ virtualenv -p `which python` venv
しかし、↓のようなエラーが飛んできた。
:::text
...
Traceback (most recent call last):
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/commands/install.py", line 267, in run
with self._build_session(options) as session:
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/basecommand.py", line 66, in _build_session
session = PipSession(
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/download.py", line 321, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/download.py", line 93, in user_agent
zip(["name", "version", "id"], platform.linux_distribution()),
AttributeError: module 'platform' has no attribute 'linux_distribution'
...
Pythonのバージョンは↓の通り。
:::text
$ python -V
Python 3.8.0b4
解決
ググってみると↓のようなログが見つかる。
- AttributeError: module 'platform' has no attribute 'linux_distribution' -- python3.8 error · Issue #3291 · PyCQA/pylint
- Как установить вирт.среду с python3.8? — Web-development — Форум
最初にpip
と周辺ツールをアップグレードする。
:::text
$ python -m pip install --upgrade pip setuptools wheel
それからvirtualenv
を使うのをやめてpython -m venv
を使うようにする。
↓は仮想環境venv
を作るコマンド。
:::text
$ python -m venv venv
これで無事に仮想環境を作成できた。
コミュニティのログを読んでいるとvirtualenv
を使うのをやめてpyenv
を使えとか、↑のようにpython -m venv
を使えとかの書き込みがあった。ちなみにこのコミュニティはロシアのコミュニティだ。ウォッカを飲んでいるとエラー解決が捗るのだろうか。