pipenv: pipenv --three generates an error on Mac OS X

I had to manually set the python variable to the correct place in the cli.py file because it was, somehow, getting the wrong path.

which('python') was returning /bin/python/ instead of the correct path.

This is the stack trace:

Virtualenv location:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1043, in invoke
    return Command.invoke(self, ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/cli.py", line 1163, in cli
    ensure_project(three=three, python=python)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/cli.py", line 382, in ensure_project
    if project.required_python_version not in python_version(path_to_python):
TypeError: argument of type 'NoneType' is not iterable

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 34 (17 by maintainers)

Most upvoted comments

Not working for me on MacOs + Brew-installed python3. However, the error went away after setting the locale so I assume this may have something to do with https://bugs.python.org/issue18378.

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Before the above mentioned exports:

$ which pip3
/usr/local/bin/pip3
$ pip3 install pipenv
Collecting pipenv
  ...
  ...
  ...
Successfully installed pipenv-7.3.7
$ pipenv --three
Warning: the environment variable LANG is not set!
We recommend setting this in ~/.profile (or equivalent) for proper expected behavior.
Creating a virtualenv for this project…
Using /usr/local/bin/python3 to create virtualenv…
...
...
Virtualenv location: 
Creating a Pipfile for this project…
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1043, in invoke
    return Command.invoke(self, ctx)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/cli.py", line 1422, in cli
    ensure_project(three=three, python=python, warn=True)
  File "/usr/local/lib/python3.6/site-packages/pipenv/cli.py", line 549, in ensure_project
    ensure_pipfile(validate=validate)
  File "/usr/local/lib/python3.6/site-packages/pipenv/cli.py", line 293, in ensure_pipfile
    project.create_pipfile(python=python)
  File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 328, in create_pipfile
    data[u'requires'] = {'python_version': python_version(python)[:len('2.7')]}
TypeError: 'NoneType' object is not subscriptable

Yeah

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

are required.

Broken here too.

SETUP:

MacOS version: 10.13.4 (High Sierra)

Python 3: brew install python pipenv: brew install pipenv

SOLUTION:

Solved by adding the following lines to ~/.bash_profile:

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Then running this command on terminal: source ~/.bash_profile

I can reproduce this bug, it depends on the Language & Region System preferences.

Good:

  1. Set Language & Region to Region=United States, Preferred Language=English. -> LANG=en_US.UTF-8
  2. pipenv works perfectly

Bad:

  1. Set Region=Germany, Preferred Language=English -> LC_CTYPE= “UTF-8”
  2. Pipenv terminates with the following traceback:

pipenv shell

Warning: the environment variable LANG is not set!
We recommend setting this in ~/.profile (or equivalent) for proper expected behavior.
Creating a virtualenv for this project…
Using /usr/local/bin/python3.6m to create virtualenv…
⠋Traceback (most recent call last):
  File "/usr/local/bin/pew", line 7, in <module>
    from pew.pew import pew
  File "/usr/local/lib/python2.7/site-packages/pew/__init__.py", line 11, in <module>
    from . import pew
  File "/usr/local/lib/python2.7/site-packages/pew/pew.py", line 42, in <module>
    from pew._utils import (check_call, invoke, expandpath, own, env_bin_dir,
  File "/usr/local/lib/python2.7/site-packages/pew/_utils.py", line 22, in <module>
    encoding = locale.getlocale()[1] or 'ascii'
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 564, in getlocale
    return _parse_localename(localename)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 477, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

Virtualenv location:
Warning: Your Pipfile requires python_version 3.6, but you are using None (/bin/python).
  $ pipenv check will surely fail.
Spawning environment shell (/bin/bash). Use 'exit' to leave.
zsmac user ~/Dropbox/sync/dev/fai-calculator/python $ source /bin/activate
bash: /bin/activate: No such file or directory

Workaround is to add

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

to .bash_profile.

sorry about the bug!

@ms4720 en_US.UTF-8

@kennethreitz just pipenv --three

Installing latest version with brew didn’t help me today, rather exporting the variables as mentioned earlier. I personally added them in ~/.bash_profile to persist, not sure whether that’s the best with MacOS.

Installed pipenv via pip3 and python3 of brew btw.

we should have this fixed within a few hours, here. this is a pretty major issue.