pipenv: .DS_Store in pyenv root cause pipenv "ValueError: Not a valid python version: "

Issue description

When trying to run pipenv sync, got ValueError: Not a valid python version: <LegacyVersion('.DS_Store')> error. Deleting ~/.pyenv/versions/.DS_Store helps.

Expected result

pipenv should ignore .DS_Store file.

Actual result

Traceback (most recent call last):
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/pythonfinder/models/pyenv.py", line 53, in get_versions
    version = PythonVersion.parse(p.name)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/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('.DS_Store')>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/vencent/.pyenv/versions/3.6.0/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/cli/command.py", line 586, in sync
    pypi_mirror=state.pypi_mirror,
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/core.py", line 2500, in do_sync
    pypi_mirror=pypi_mirror,
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/core.py", line 565, in ensure_project
    pypi_mirror=pypi_mirror,
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/core.py", line 488, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/core.py", line 401, in ensure_python
    path_to_python = find_a_system_python(python)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/core.py", line 364, in find_a_system_python
    python_entry = finder.find_python_version(line)
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 90, in find_python_version
    return self.system_path.find_python_version(
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 44, in system_path
    ignore_unsupported=self.ignore_unsupported,
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/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 "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/pythonfinder/models/path.py", line 102, in __attrs_post_init__
    self._setup_pyenv()
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/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 "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/pythonfinder/models/pyenv.py", line 98, in create
    return cls(root=root, ignore_unsupported=ignore_unsupported)
  File "<attrs generated init 622376ddae498c76611d8b35810e09515a0b8478>", line 7, in __init__
  File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv/vendor/pythonfinder/models/pyenv.py", line 58, in get_versions
    if not version:
UnboundLocalError: local variable 'version' referenced before assignment

Steps to replicate

(This happens on Mac, since .DS_Store is a macOS auto-generated file) Put a .DS_Store under pyenv’s versions folder


$ pipenv --support

Pipenv version: '2018.10.13'

Pipenv location: '/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pipenv'

Python location: '/Users/vencent/.pyenv/versions/3.6.0/bin/python3.6'

Python installations found:

  • 3.6.0: /Users/vencent/.pyenv/shims/python3
  • 3.6.0: /Users/vencent/.pyenv/shims/python
  • 3.6.0: /Users/vencent/.pyenv/shims/python3.6
  • 3.6.0: /Users/vencent/.pyenv/shims/python3.6m
  • 3.6.0: /Users/vencent/.pyenv/versions/3.6.0/bin/python3.6
  • 3.6.0: /Users/vencent/.pyenv/versions/3.6.0/bin/python3.6m
  • 3.5.0: /Users/vencent/.pyenv/versions/3.5.0/bin/python3.5
  • 3.5.0: /Users/vencent/.pyenv/versions/3.5.0/bin/python3.5m
  • 2.7.14: /usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/bin/python2.7
  • 2.7.10: /usr/bin/python
  • 2.7.10: /usr/bin/pythonw
  • 2.7.10: /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
  • 2.7: /Users/vencent/.pyenv/versions/2.7/bin/python
  • 2.7: /Users/vencent/.pyenv/versions/2.7/bin/python2.7

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.6.0',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '18.0.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT '
                     '2018; root:xnu-4903.201.2~1/RELEASE_X86_64',
 'python_full_version': '3.6.0',
 'python_version': '3.6',
 'sys_platform': 'darwin'}

System environment variables:

  • AUTOJUMP_ERROR_PATH
  • MODE
  • PYENV_ROOT
  • AUTOJUMP_SOURCED
  • TERM
  • SHELL
  • CLICOLOR
  • TMPDIR
  • Apple_PubSub_Socket_Render
  • PYENV_VERSION
  • LC_ALL
  • ZSH
  • http_proxy
  • USER
  • SSH_AUTH_SOCK
  • PYENV_DIR
  • __CF_USER_TEXT_ENCODING
  • PAGER
  • LSCOLORS
  • all_proxy
  • PATH
  • PWD
  • SENTRY_URL
  • LANG
  • PYENV_HOOK_PATH
  • XPC_FLAGS
  • SENTRY_AUTH_TOKEN
  • https_proxy
  • XPC_SERVICE_NAME
  • PYENV_SHELL
  • SHLVL
  • HOME
  • SENTRY_ORG
  • LESS
  • LOGNAME
  • LC_CTYPE
  • PYTHONDONTWRITEBYTECODE
  • PIP_SHIMS_BASE_MODULE
  • PIP_PYTHON_PATH

Pipenv–specific environment variables:

Debug–specific environment variables:

  • PATH: /Users/vencent/.pyenv/versions/3.6.0/bin:/usr/local/Cellar/pyenv/1.0.10/libexec:/Users/vencent/.pyenv/shims:/Users/vencent/.pyenv/bin:/Applications/CMake.app/Contents/bin:/opt/local/bin:/opt/local/sbin:/Users/vencent/Qt5.9.0/5.9/clang_64/bin:/Users/vencent/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
  • SHELL: /bin/zsh
  • LANG: en_US.UTF-8
  • PWD: /Users/vencent/.pyenv/versions

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 25 (7 by maintainers)

Most upvoted comments

Yeah, sorry to bug about this but it’s been a really annoying couple of hours for me.

For all who look into this problem on their own:

  • look for .DS_Store up to your home folder (IIRC pyenv will look in the folder hierarchy for a python version file
  • if you installed via Homebrew (on a Mac) have a look at your HOMEBREW_PREFIX (i.e. /usr/local) for a .DS_Store and get rid of it. Here’s how to search for it on a terminal :find /usr/local/var/pyenv/versions -name ".DS_Store"

Just remove ~/.pyenv/versions/.DS_Store, then run pipenv install again. Everything goes fine.

Today I saw the original error message from pipenv==2018.10.13, and the related error below from 2018.11.26.

Deleting ~/.pyenv/versions/.DS_Store still helps, fortunately!

$ pipenv install

Traceback (most recent call last):
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/python.py", line 112, in get_versions
    version = PythonVersion.parse(p.name)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/python.py", line 359, in parse
    version_dict = parse_python_version(str(version))
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/utils.py", line 86, in parse_python_version
    raise InvalidPythonVersion("%s is not a python version" % version_str)
pipenv.vendor.pythonfinder.exceptions.InvalidPythonVersion: .DS_Store is not a python version

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/psm/.pyenv/versions/3.7.1/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/cli/command.py", line 254, in install
    editable_packages=state.installstate.editables,
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/core.py", line 1741, in do_install
    pypi_mirror=pypi_mirror,
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/core.py", line 574, in ensure_project
    pypi_mirror=pypi_mirror,
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/core.py", line 494, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/core.py", line 397, in ensure_python
    path_to_python = find_a_system_python(python)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/core.py", line 360, in find_a_system_python
    python_entry = finder.find_python_version(line)
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 113, in find_python_version
    return self.system_path.find_python_version(
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 54, in system_path
    ignore_unsupported=self.ignore_unsupported,
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/path.py", line 451, in create
    ignore_unsupported=ignore_unsupported,
  File "<attrs generated init 75e45f144e3d5510d54dd5fca6730b98fa0220a9>", line 38, in __init__
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/path.py", line 116, in __attrs_post_init__
    self._setup_pyenv()
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/path.py", line 196, in _setup_pyenv
    version_glob_path="versions/*", ignore_unsupported=self.ignore_unsupported
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/python.py", line 156, in create
    sort_function=sort_function, version_glob_path=version_glob_path)
  File "<attrs generated init a1a05d8eafbd2700b304c565646ba66e3f0eaec0>", line 17, in __init__
  File "/Users/psm/.pyenv/versions/3.7.1/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/python.py", line 114, in get_versions
    entry = next(iter(version_path.find_all_python_versions()), None)
AttributeError: 'NoneType' object has no attribute 'find_all_python_versions'

I think this “closed” issue should be revisited. While using pipenv, version 2018.11.26, and upon executing the pipenv install command, I too observed the following: AttributeError: 'NoneType' object has no attribute 'find_all_python_versions'

I tried executing pipenv install --dev lettuce (after reading the pipenv docs regarding the Pipfile) and the result was:

AttributeError: 'NoneType' object has no attribute 'find_all_python_versions'
...
raise InvalidPythonVersion("%s is not a python version" % version_str)
pipenv.vendor.pythonfinder.exceptions.InvalidPythonVersion: .DS_Store is not a python version

I removed the ~/.pyenv/versions/.DS_Store as indicated above as a possible solution. I then re-executed pipenv install --dev lettuce and happily observed:

Practice/Python Playground/myBankAccount
➜ pipenv install --dev lettuce
Creating a Pipfile for this project…
Installing lettuce…
Adding lettuce to Pipfile's [dev-packages]…
✔ Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
✔ Success!
Locking [packages] dependencies…
Updated Pipfile.lock (7b489f)!
Installing dependencies from Pipfile.lock (7b489f)…
  🎅   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 15/15 — 00:00:03
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

Perhaps pipenv should explicitedly ignore the .DS_Store file on a Mac(?). Cheers!

rm ~/.pyenv/versions/.DS_Store works for me.

I had one in two places… I think a better version is:

find ~/.pyenv -name ".DS_Store" -delete

rm ~/.pyenv/versions/.DS_Store works for me.

Just for the record, this issue still exists. https://github.com/pypa/pipenv/issues/3208#issuecomment-471241648 helps but is cumbersome.

We have a fix merged for this already and should be releasing today

Thank you for that, @fr0der1c! I was able to continue using pipenv for now by installing it with python3 -m pip install pipenv==2018.10.13 --user.

😂The latest version is completely broken(#3224, even setting pyenv global version won’t help) and I have to downgrade to 2018.10.13 again.

@timburgess same for me Ubuntu 18.10! Keep me posted, if you do find anything!