Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
massenz opened this issue Nov 24, 2018 · 8 comments
Labels
Type: Duplicate This issue is a duplicate of an already-existing issue.

Comments

@massenz
Copy link

massenz commented Nov 24, 2018

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+')>
@massenz massenz changed the title pipenv install fails with "Not a valid python version" even if python3 is on the path pipenv 2018.11.14 fails with "Not a valid python version" when installed via pip on a system that has Python 2.7 Nov 24, 2018
@massenz
Copy link
Author

massenz commented Nov 24, 2018

Getting the same error while running pipenv --support made me realize the issue was with pipenv and not my choosing --python 3.6.

I unistalled it, and re-installed a previous release:

└─( sudo -H pip install pipenv==2018.10.13

and this is now working again on my system.

I believe the issue here is that the latest pipenv requires Python 3, but when installed on a system with 2.7 as the default (I am running Ubuntu 18.10) it fails.

Not sure how to make it work (i.e., make it so that the pipenv binary is executed using python3 instead of python) nor this appears to be documented anywhere.

pipenv 2018.10.13 works just fine on my system:

└─( pipenv --python 3.6 install
Creating a virtualenv for this project…
Pipfile: /home/marco/workspaces/main/serverless/python/Pipfile
Using /usr/bin/python3.6 (3.6.7) to create virtualenv…
⠇Running virtualenv with interpreter /usr/bin/python3.6
Using base prefix '/usr'
New python executable in /home/marco/.virtualenv/python-AO51eeIn/bin/python3.6
Also creating executable in /home/marco/.virtualenv/python-AO51eeIn/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /home/marco/.virtualenv/python-AO51eeIn
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (a1fb3b)!
Installing dependencies from Pipfile.lock (a1fb3b)…
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 32/32 — 00:00:07
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

@jxltom
Copy link
Contributor

jxltom commented Nov 24, 2018

It looks like <LegacyVersion('2.7.15+') is not successfully parsed by pythonfinder

@jxltom jxltom added Type: Vendored Dependencies This issue affects vendored dependencies within pipenv. Type: Bug 🐛 This issue is a bug. labels Nov 24, 2018
@jxltom
Copy link
Contributor

jxltom commented Nov 24, 2018

Oh, I think it is duplicated with #3241 which is already fixed in #3254. Could you try the latest master branch of pipenv? That should solve your problem.

@jxltom jxltom added Type: Duplicate This issue is a duplicate of an already-existing issue. and removed Type: Bug 🐛 This issue is a bug. Type: Vendored Dependencies This issue affects vendored dependencies within pipenv. labels Nov 24, 2018
@techalchemy
Copy link
Member

I'll have the last bugfix before the release up and building, but yeah, this is another pythonfinder issue unfortunately -- it's fixed in master but not released yet.

I'm going to close this for now (you'll be able to fix by upgrading in a few hours), sorry for the trouble!

P.S. You should avoid using sudo pip <x> at all costs if possible, it's a good way to really mess your system up -- ubuntu and most other distributions repackage most python packages as they have system level dependencies on those packages. For example, apt requires specific python components to be fully functional, and you can definitely mess those up by using sudo pip install -- consider using pyenv or at the very least using --user to manage the separation

@massenz
Copy link
Author

massenz commented Nov 24, 2018

Hey - super-thanks for jumping on this one so quickly, appreciated!

Absolutely no trouble, I'll update my version once it's ready.

You should avoid using sudo pip at all costs if possible, it's a good way to really mess your system up

No kidding! I'm always super-careful with the system distro, which is why is have been using virtualenv and now pipenv; unfortunately, it's a bit of a catch-22: in order to use either, they need to be installed on the system python; I only upgrade (manually, via pip) only pip itself, virtualenv and (now) pipenv -- everything else, it's apt-get all the way down.

@Wyzzard123
Copy link

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

@mrhyun
Copy link

mrhyun commented Sep 6, 2020

Using pip install pipenv==2018.10.13 like Wyzzard123 mentioned fixed the problem for me. I was stuck in Anaconda3 not being a vlid python path before

@jg185366
Copy link

jg185366 commented Oct 5, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Duplicate This issue is a duplicate of an already-existing issue.
Projects
None yet
Development

No branches or pull requests

6 participants