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.

pipenv 2018.11.14 fails with "Not a valid python version" when installed via pip on a system that has Python 2.7

See original GitHub issue

Issue description

When I run this: pipenv --python 3.6 install

it fails even if both python3 and python3.6 are on the PATH:

└─( which python
/usr/bin/python

└─( which python3
/usr/bin/python3

└─( python3 --version
Python 3.6.7

└─( which python3.6
/usr/bin/python3.6

Expected result

pipenv should be sufficiently smart to figure it out by itself that python3.6 is the desired binary.

Actual result

This is the error, full stacktrace at the bottom:

  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/python.py", line 366, in parse
    raise ValueError("Not a valid python version: %r" % version)
ValueError: Not a valid python version: <LegacyVersion('2.7.15+')>

Steps to replicate

See below.


Please run $ pipenv --support, and paste the results here.

$ pipenv --support | xclip
$ pipenv --support

Pipenv version: '2018.11.14'

Pipenv location: '/usr/local/lib/python2.7/dist-packages/pipenv'

Python location: '/usr/bin/python'

Python installations found:

(and, LoL - --support fails with the same error)


Full Stacktrace

└─( pipenv --python 3.6 install
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 1134, in invoke
    Command.invoke(self, ctx)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/cli/command.py", line 203, in cli
    clear=state.clear,
  File "/usr/local/lib/python2.7/dist-packages/pipenv/core.py", line 569, in ensure_project
    pypi_mirror=pypi_mirror,
  File "/usr/local/lib/python2.7/dist-packages/pipenv/core.py", line 489, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/core.py", line 397, in ensure_python
    path_to_python = find_a_system_python(python)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/core.py", line 360, in find_a_system_python
    python_entry = finder.find_python_version(line)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/backports/functools_lru_cache.py", line 137, in wrapper
    result = user_function(*args, **kwds)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 114, in find_python_version
    major=major, minor=minor, patch=patch, pre=pre, dev=dev, arch=arch, name=name
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/path.py", line 396, in find_python_version
    ver = next(iter(self.get_pythons(sub_finder)), None)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/path.py", line 279, in get_pythons
    reverse=True
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/path.py", line 277, in <genexpr>
    (p for p in self._filter_paths(finder) if p.is_python),
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/path.py", line 264, in <genexpr>
    pth for pth in unnest(finder(p) for p in self.path_entries if p is not None)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/utils.py", line 138, in unnest
    for el in target:
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/path.py", line 264, in <genexpr>
    pth for pth in unnest(finder(p) for p in self.path_entries if p is not None)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/mixins.py", line 121, in find_python_version
    for child in unnest(self.pythons.values())
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/path.py", line 523, in pythons
    for path, entry in self.children.items():
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/path.py", line 494, in children
    for child_key, child_val in self._gen_children():
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/path.py", line 487, in _gen_children
    yield (child.as_posix(), PathEntry.create(path=child, **pass_args))
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/path.py", line 567, in create
    _new = cls(**creation_args)
  File "<attrs generated init a309dc529103f000f3a8248fa1855f93d8af58ae>", line 16, in __init__
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/path.py", line 510, in get_py_version
    py_version = PythonVersion.from_path(path=self, name=self.name)
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/python.py", line 418, in from_path
    instance_dict = cls.parse(py_version.strip())
  File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/pythonfinder/models/python.py", line 366, in parse
    raise ValueError("Not a valid python version: %r" % version)
ValueError: Not a valid python version: <LegacyVersion('2.7.15+')>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Wyzzard123commented, Aug 20, 2020

Facing this problem 2 years later on a windows computer. First it told me that Anaconda3 wasn’t a valid python path. Then I installed Anaconda and it told me that 2.7 wasn’t a valid python path.

What finally worked for me was massenz’s solution to just install the older version of pipenv: pip install pipenv==2018.10.13

0reactions
jg185366commented, Oct 5, 2021

I’m still encountering this issue on pipenv-2021.5.29. Installing the version mentioned above fixed my issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is pipenv telling me the wrong version of python?
It scans your system and looks for a compatible python installation. Now, it seems you already have an existing Pipfile that has "2.7"...
Read more >
pipenv · PyPI
Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python...
Read more >
Pipenv: Python Dev Workflow for Humans — pipenv 2022.12 ...
Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, ... Automatically install required Python version when pyenv...
Read more >
pipenv Documentation - Read the Docs
Generates and checks file hashes for locked dependencies when installing from Pipfile.lock. • Automatically install required Python version when pyenv is ...
Read more >
Configure a Pipenv environment | PyCharm Documentation
Run the following command to ensure you have pip installed in your system: ... to expand the Python Interpreter node, select New environment...
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