LegacyVersion('anaconda3-5.3.1')というエラー
% pipenv --three
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/pyenv.py", line 53, in get_versions
version = PythonVersion.parse(p.name)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/python.py", line 119, in parse
raise ValueError("Not a valid python version: %r" % version)
ValueError: Not a valid python version: <LegacyVersion('anaconda3-5.3.1')>
...
こんなエラーが出た。LegacyVersion('anaconda3-5.3.1')
らしい。
Anaconda installer archiveによると2018-11-19リリース版。なのにレガシー。
そもそもAnacondaは使ってない
% python --version
3.7.3
% which python
/Users/user/.anyenv/envs/pyenv/shims/python
デフォルトは現在最新の3.7.3を有効にしている。anacondaは使ってない。
このanaconda、どこから来たのか。
複数環境をスイッチさせてる中にanacondaを入れるとよくないという話を聞くが、こういうことが起こるからだろうか。
アナコンダは気質に悪評があり、さらにオオアナコンダは大きすぎるので、ボアと比べるとペットとしては人気がない。
アナコンダ - Wikipedia
ペットでもアナコンダは人気無いようですし(関係ない)。
手探りしてたら、pipenvの初期化でパスが通ったpythonのバージョンを指定したら通った。
% pipenv --python `which python`
Creating a virtualenv for this project…
Pipfile: /Users/user/Documents/workspace/sandobox/Pipfile
Using /Users/user/.anyenv/envs/pyenv/shims/python (3.7.0) to create virtualenv…
⠏Running virtualenv with interpreter /Users/user/.anyenv/envs/pyenv/shims/python
Using base prefix '/Users/user/.anyenv/envs/pyenv/versions/anaconda3-5.3.1'
/usr/local/lib/python3.7/site-packages/virtualenv.py:1041: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
New python executable in /Users/user/Documents/workspace/sandobox/.venv/bin/python
Installing setuptools, pip, wheel...done.
Virtualenv location: /Users/user/Documents/workspace/sandobox/.venv
Creating a Pipfile for this project…
この指定で動くのも、また謎すぎる。
Using base prefix '/Users/user/.anyenv/envs/pyenv/versions/anaconda3-5.3.1'
というログが残ってるから、強引に置き換えて無理やり動かした感じがする。
やっぱり動かない
% pipenv shell
Warning: Your Pipfile requires python_version 3.7, but you are using None (/Users/user/D/w/s/.venv/bin/python).
$ pipenv --rm and rebuilding the virtual environment may resolve the issue.
$ pipenv check will surely fail.
Launching subshell in virtual environment…
. /Users/user/Documents/workspace/sandbox/.venv/bin/activate
% . /Users/user/Documents/workspace/sandbox/.venv/bin/activate
pipenv shell
をすると警告が出た。いちおう、shellには入れる。
(sandbox) % pipenv install requests
Warning: Your Pipfile requires python_version 3.7, but you are using None (/Users/user/D/w/s/.venv/bin/python).
$ pipenv --rm and rebuilding the virtual environment may resolve the issue.
$ pipenv check will surely fail.
Installing requests…
⠋
Error: An error occurred while installing requests!
/bin/sh: /Users/user/Documents/workspace/sandbox/.venv/bin/pip: /Users/user/Documents/workspace/proxy/.venv/bin/python: bad interpreter: No such file or directory
installが使えないので、やはり正常にインストールされてなかった。
Anacondaを消してみる
Anacondaを消して、再度pipenvしてみる。
% pyenv uninstall anaconda anaconda3-5.3.1
pyenv: remove /Users/user/.anyenv/envs/pyenv/versions/anaconda3-5.3.1? y
% pyenv versions
system
* 3.7.3 (set by /Users/user/.anyenv/envs/pyenv/version)
% rm .venv
% pipenv --three
Creating a virtualenv for this project…
Pipfile: /Users/user/Documents/workspace/sandbox/Pipfile
Using /Users/user/.anyenv/envs/pyenv/shims/python3 (3.7.3) to create virtualenv…
⠧Running virtualenv with interpreter /Users/user/.anyenv/envs/pyenv/shims/python3
Using base prefix '/Users/user/.anyenv/envs/pyenv/versions/3.7.3'
/usr/local/lib/python3.7/site-packages/virtualenv.py:1041: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
New python executable in /Users/user/Documents/workspace/sandbox/.venv/bin/python3
Also creating executable in /Users/user/Documents/workspace/sandbox/.venv/bin/python
Installing setuptools, pip, wheel...done.
Virtualenv location: /Users/user/Documents/workspace/sandbox/.venv
動いた。
Anacondaが最新だったら
Anacondaが古いからダメなのかもしれないと思い、最新のAnacondaを入れて、再度pipenvをしてみる。
% pyenv install anaconda3-2019.03
Downloading Anaconda3-2019.03-MacOSX-x86_64.sh...
-> https://repo.continuum.io/archive/Anaconda3-2019.03-MacOSX-x86_64.sh
Installing Anaconda3-2019.03-MacOSX-x86_64...
Installed Anaconda3-2019.03-MacOSX-x86_64 to /Users/user/.anyenv/envs/pyenv/versions/anaconda3-2019.03
% pyenv versions
system
* 3.7.3 (set by /Users/user/.anyenv/envs/pyenv/version)
anaconda3-2019.03
% pipenv --three
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/pyenv.py", line 53, in get_versions
version = PythonVersion.parse(p.name)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/python.py", line 119, in parse
raise ValueError("Not a valid python version: %r" % version)
ValueError: Not a valid python version: <LegacyVersion('anaconda3-2019.03')>
...
やはりエラーになる。LegacyVersionって、それ現在の最新版ですよ!
どうやらpyenvにAnacondaを混ぜるとよくないらしい。
ビルドインのpipenvを使わなければ動く
pyenvで入れたPythonにPipenvをインストールすれば動く。
% which pipenv
/usr/local/bin/pipenv
% pip install pipenv
...
% which pipenv
/Users/user/.anyenv/envs/pyenv/shims/pipenv
% pipenv --three
Creating a virtualenv for this project…
Pipfile: /Users/user/Documents/workspace/sandbox/Pipfile
Using /Users/user/.anyenv/envs/pyenv/versions/3.7.3/bin/python3 (3.7.3) to create virtualenv…
⠧ Creating virtual environment...Already using interpreter /Users/user/.anyenv/envs/pyenv/versions/3.7.3/bin/python3
Using base prefix '/Users/user/.anyenv/envs/pyenv/versions/3.7.3'
New python executable in /Users/user/Documents/workspace/sandbox/.venv/bin/python3
Also creating executable in /Users/user/Documents/workspace/sandbox/.venv/bin/python
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /Users/user/.anyenv/envs/pyenv/versions/3.7.3/bin/python3
✔ Successfully created virtual environment!
Virtualenv location: /Users/user/Documents/workspace/sandbox/.venv
今までPipenvはMacのビルドイン版を使ってたけど、こっちのほうがいいのかな。
エラーログ(検索用)
% pipenv --three
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/pyenv.py", line 53, in get_versions
version = PythonVersion.parse(p.name)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/python.py", line 119, in parse
raise ValueError("Not a valid python version: %r" % version)
ValueError: Not a valid python version: <LegacyVersion('anaconda3-5.3.1')>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/pipenv", line 11, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1114, in invoke
return Command.invoke(self, ctx)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pipenv/cli/command.py", line 203, in cli
clear=state.clear,
File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 565, in ensure_project
pypi_mirror=pypi_mirror,
File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 488, in ensure_virtualenv
python = ensure_python(three=three, python=python)
File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 401, in ensure_python
path_to_python = find_a_system_python(python)
File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 364, in find_a_system_python
python_entry = finder.find_python_version(line)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 90, in find_python_version
return self.system_path.find_python_version(
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 44, in system_path
ignore_unsupported=self.ignore_unsupported,
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/path.py", line 309, in create
ignore_unsupported=ignore_unsupported,
File "<attrs generated init 21cfbcaf749d3af30eb10d5110d156423170deac>", line 37, in __init__
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/path.py", line 102, in __attrs_post_init__
self._setup_pyenv()
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/path.py", line 133, in _setup_pyenv
self.pyenv_finder = PyenvFinder.create(root=PYENV_ROOT, ignore_unsupported=self.ignore_unsupported)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/pyenv.py", line 98, in create
return cls(root=root, ignore_unsupported=ignore_unsupported)
File "<attrs generated init e2de76c84a062f4c9c55ad2f5f11c1f2c8b33679>", line 7, in __init__
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/pyenv.py", line 57, in get_versions
version = self.version_from_bin_dir(bin_dir)
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/pyenv.py", line 36, in version_from_bin_dir
version = get_python_version(py.as_posix())
File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/utils.py", line 41, in get_python_version
raise InvalidPythonVersion("%s is not a valid python path" % path)
pipenv.vendor.pythonfinder.exceptions.InvalidPythonVersion: /Users/user/.anyenv/envs/pyenv/versions/anaconda3-5.3.1/bin/anaconda is not a valid python path