Recent versions of pipenv no longer work with pypy3.
Expected pipenv to work.
❯ PYENV_VERSION=pypy3.5-6.0.0 pyenv exec pipenv --verbose
Traceback (most recent call last):
File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/bin/pipenv", line 7, in <module>
from pipenv import cli
File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/__init__.py", line 47, in <module>
from .cli import cli
File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/cli/__init__.py", line 3, in <module>
from .command import cli
File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/cli/command.py", line 19, in <module>
from .options import (
File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/cli/options.py", line 11, in <module>
from .. import environments
File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/environments.py", line 7, in <module>
from ._compat import fix_utf8
File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/_compat.py", line 98, in <module>
OUT_ENCODING, ERR_ENCODING = force_encoding()
File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/_compat.py", line 68, in force_encoding
from ctypes import pythonapi, py_object, c_char_p
ImportError: cannot import name 'pythonapi'
Simply install pipenv with PyPy3, then try to run any pipenv command.
pipenv --support
won't work either.
PyPy doesn't support ctypes.pythonapi
, but the root cause of the issue is that it shouldn't even try to import this module in the first place. I've investigated a bit and it looks with PyPy3, sys.stdout.encoding
returns "utf8"
instead of "utf-8"
. I'm unsure whether this is a PyPy bug or not, but since pipenv used to work fine with PyPy3 prior to (I think) #3096, can we relax the condition on this line to allow for "utf8"
as well as "utf-8"
?
Pipenv is not guaranteed to work on PyPy, nor is PyPy included in our CI setup.
Well, PyPy appears in setup.py classifiers? That should be removed, sorry for the trouble.
Hey @frostming, thanks for the reply. It's a bit disappointing to hear that PyPy isn't officially supported, as it means that packages that _do_ support PyPy need to introduce additional complexity to use pipenv only on supported Python versions or not use pipenv at all.
Also, regarding the exact issue I described, I suspect this _is_ a bug in pipenv:
__init__.py
, sys.stdout
and sys.stderr
are replaced by io.TextIOWrapper
s with encoding
set to 'utf8'
(no dash): https://github.com/pypa/pipenv/blob/d9ebad335dc4cfff9cb223f7cc3141066044b65b/pipenv/__init__.py#L31-L36_compat.py
, the encoding is forced to UTF-8 by checking if sys.stdout/err.encoding.lower()
is equal to 'utf-8'
(with a dash): https://github.com/pypa/pipenv/blob/d9ebad335dc4cfff9cb223f7cc3141066044b65b/pipenv/_compat.py#L331Good catch, would like to send a PR for it?
Certainly :) Will send one in a moment!
PR submitted: https://github.com/pypa/pipenv/pull/3322
I have no real qualms fixing PyPy support as it shouldn’t be hard...
I was caught off guard with this bug with Pypy3 too. This doesn't trigger any error with Cpython as it has a module ctype to import.
Glad to know this has been fixed !
Just noting that I just ran into this in Circle CI -- Since the #3322 PR hasn't landed in a release yet I'm going to attempt to use pipenv
from master
for the time being.
Most helpful comment
PR submitted: https://github.com/pypa/pipenv/pull/3322