question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.DS_Store in pyenv root cause pipenv "ValueError: Not a valid python version: <LegacyVersion('.DS_Store')>"

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

11reactions
oerdcommented, Dec 29, 2018

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"
10reactions
waysupcommented, Mar 10, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is Pipenv not picking up my Pyenv versions?
While I still can't get it to recognize the python version activated with pyenv shell x.x.x , by removing the PIPENV_PYTHON environment variable ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found