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

crayons TypeError in core.py #2609

Closed
mehrdadbaqeri opened this issue Jul 18, 2018 · 12 comments
Closed

crayons TypeError in core.py #2609

mehrdadbaqeri opened this issue Jul 18, 2018 · 12 comments
Labels
Status: Needs More Information This issue does not provide enough information to take further action.

Comments

@mehrdadbaqeri
Copy link

I am having a special setup. I have a docker in which I create an emulated ARM rootfs using QEMU. Inside the emulated rootfs , I am going to create a virtual environment using pipenv which I can use later on my ARM target.
What is happening now is that I am always receiving the following exception:

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 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_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/cli.py", line 416, in install
    selective_upgrade=selective_upgrade,
  File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 1789, in do_install
    skip_requirements=skip_requirements,
  File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 641, in ensure_project
    crayons.green(shorten_path(path_to_python)),
TypeError: __str__ returned non-string (type NoneType)

As I traced the exception, I found out that problem here is that the python_version() method returns None in my case. Then as I use docker exec to run pipenv install, I think I am mixing different shell environment, therefore crayons.green cannot convert None type to string. My proposal would be simply just use str in all crayons e.g. crayons.green(str(python_version(path_to_python)))

@techalchemy
Copy link
Member

Please tell us all of the information about the pipenv version running in your environment, per the issue template,

I realize it may seem intuitive to you what is happening, but pipenv is super complex and what you think is happening is probably more involved than you're suggesting, so before we jump to any conclusions or start deciding what the solution is, it would be good to diagnose the problem

@techalchemy techalchemy added the Status: Needs More Information This issue does not provide enough information to take further action. label Jul 18, 2018
@mehrdadbaqeri
Copy link
Author

Well, of course it was a proposal to give you little bit more information about hot fix which I made after spending hours on checking from top to down in docker and QEMU emulator. However, I am using pipenv version 2018.7.1 and python version 3.6.3 in the emulator.

@uranusjr
Copy link
Member

uranusjr commented Jul 19, 2018

Wild guess, does setting PIPENV_COLORBLIND inside the emulator work? Maybe QEMU doesn’t like ANSI colour codes.

https://docs.pipenv.org/advanced/#pipenv.environments.PIPENV_COLORBLIND

@mehrdadbaqeri
Copy link
Author

I just tried with PIPENV_COLORBLIND set. I have the same issue again. What I have to add is that when I manually log into my docker container and manually run pipenv install in the emulated QEMU rootfs, everything is fine and it works, but as soon as I try the same thing using docker exec outside of the docker, I will have the exception. The point is that crayons once can get __str__ out of None, but not in the case when I use docker exec!

@uranusjr
Copy link
Member

I think I kind of know what the root problem is. Crayon can only return None when the input is None, which means that ultimately path_to_python is None, which leads us back to system_which returning None… this problem, maybe?

https://docs.pipenv.org/diagnose/#valueerror-unknown-locale-utf-8

@mehrdadbaqeri
Copy link
Author

Actually the path_to_python is equal /usr/bin/python when it is delivered to utils.python_version. I do not know what happens there that utils.python_version returns None. As I said before, crayons can only handle strings, and what is unclear for me is the point that in one way it is able to get "None" out of None.__str__, but not in the other way.

@uranusjr
Copy link
Member

Literally no code paths in crayons can return None if the input string is not None. This error can only occur when path_to_python is None. Believe me, or I can offer nothing else.

@sikmir
Copy link

sikmir commented Jul 19, 2018

I have the same problem with python-3.7 and pipenv-2018.7.1:

Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/pipenv/cli.py", line 701, in run
    do_run(command=command, args=args, three=three, python=python, pypi_mirror=pypi_mirror)
  File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 2244, in do_run
    ensure_project(three=three, python=python, validate=False, pypi_mirror=pypi_mirror)
  File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 625, in ensure_project
    crayons.green(shorten_path(path_to_python)),
TypeError: __str__ returned non-string (type NoneType)

@techalchemy
Copy link
Member

Please fill out the issue template in full. The bug is not in crayons no matter how many times we see the same output. We have issue templates for a reason. I appreciate that everyone is taking time to troubleshoot, we also spent months (or years) building the library and if you can't spend the time to fill out an issue template we can't offer you any support.

@semiversus
Copy link

Here are two other issues addressing the same problem: #2650, #1969 . And as already mentioned something in detection of used python version is broken. For me adding --system (pipenv install --system) solved the issue.

@YVCodeArtisan
Copy link

What does "System pip management" mean (from the documentation of the --system flag)?

@mindflayer
Copy link

mindflayer commented Feb 19, 2020

Same problem here, working within a Docker container.
Host environment is:

$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
$ docker --version
Docker version 18.09.7, build 2d0083d
$ docker-compose --version
docker-compose version 1.25.4, build unknown

Python container is based on

FROM python:3.7-slim-buster

and it uses the following pipenv version:

pipenv = "==2018.11.26"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs More Information This issue does not provide enough information to take further action.
Projects
None yet
Development

No branches or pull requests

7 participants