Thursday, March 23, 2017

pip is broken

Help?

Since asking people to use pip to install things, I get a lot of feedback on pip not working. Feedback like this.

"Our fun packaging Jargon"


What is a pip? What's it for? It's not built into python?  It's the almost-default and almost-standard tool for installing python code. Pip almost works a lot of the time. You install things from pypi. I should download pypy? No, pee why, pee eye. The cheeseshop. You're weird. Just call it pee why pee eye. But why is it called pip? I don't know.

"Feedback like this."

pip is broken on the raspberian

pip3 doesn't exist on windows

People have an old pip. Old pip doesn't support wheels. What are wheels? It's a cute bit of jargon to mean a zip file with python code in it structured in a nice way. I heard about eggs... tell me about eggs? Well, eggs are another zip file with python code in it. Used mainly by easy_install. Easy install? Let's use that, this is all too much.

The pip executable or script is for python 2, and they are using python 3.

pip is for a system python, and they have another python installed. How did they install that python? Which of the several pythons did they install? Maybe if they install another python it will work this time.

It's not working one time and they think that sudo will fix things. And now certain files can't be updated without sudo. However, now they have forgotten that sudo exists.

"pip lets you run it with sudo, without warning."


pip doesn't tell them which python it is installing for. But I installed it! Yes you did. But which version of python, and into which virtualenv? Let's use these cryptic commands to try and find out...

pip doesn't install things atomically, so if there is a failed install, things break. If pip was a database (it is)...

Virtual environments work if you use python -m venv, but not virtualenv. Or some times it's the other way around. If you have the right packages installed on Debian, and Ubuntu... because they don't install virtualenv by default.

What do you mean I can't rename my virtualenv folder? I can't move it to another place on my Desktop?

pip installs things into global places by default.

"Globals by default."


Why are packages still installed globally by default?

"So what works currently most of the time?"


python3 -m venv anenv
. ./anenv/bin/activate
pip install pip --upgrade
pip install pygame


This is not ideal. It doesn't work on windows. It doesn't work on Ubuntu. It makes some text editors crash (because virtualenvs have so many files they get sick). It confuses test discovery (because for some reason they don't know about virtual environments still and try to test random packages you have installed). You have to know about virtualenv, about pip, about running things with modules, about environment variables, and system paths. You have to know that at the beginning. Before you know anything at all.

Is there even one set of instructions where people can have a new environment, and install something? Install something in a way that it might not break their other applications? In a way which won't cause them harm? Please let me know the magic words?

I just tell people `pip install pygame`. Even though I know it doesn't work. And can't work. By design. I tell them to do that, because it's probably the best we got. And pip keeps getting better. And one day it will be even better.

Help? Let's fix this.

8 comments:

Dan Clark said...

Some have advocated that the activate script should not be used. Instead create an environment variable that points to the virtual environment and use that instead. That way there is no confusion as to what is being affected.

I have also found that this makes using sudo less painful as you are explicitly telling it which pip to use.

This might be helpful if you haven't seen it.
https://gist.github.com/datagrok/2199506

Also, I was exposed to this approach with the pyramid framework
http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/install.html#installing-pyramid-on-a-unix-system

Tim said...

Some of those comments about pip are broad and vague like "pip doesn't work on raspbian" . I use it nearly every day on raspbian, and works fine. So qualification is possibly required. Most of the problem you describe I don't generally experience. I develop on windows and linix (ubuntu and raspbian). I user virtualenv. But most of my work is still in 2.7

Rene Dudfield said...

A lot of the problems mentioned here are not problems for lots of people. They're other peoples problems.

It's broad and vague, and yet it was feedback I got. Even recently from a technical person who works for the Raspberry pi foundation.

Rene Dudfield said...

Thanks Dan. I think having per platform instructions is the way to go at the moment.

ricardo said...

Some of the issues you mention are addressed by fades (https://github.com/PyAr/fades).
It's a wrapper around pip that hides all the virtualenv details away from the user and just does the right thing, eg

fades -d pygame myscript.py

will create a virtualenv with pygame installed in it and then use that virtualenv to run myscript.py

ajasja said...

I believe conda solves all these problems.
https://github.com/conda/conda

Mark Lawrence said...

If pip3 doesn't exist on windows what is the following?

Directory of c:\Program Files\Python36\scripts

22/03/2017 05:53 98,141 pip.exe
22/03/2017 05:53 98,141 pip3.6.exe
22/03/2017 05:53 98,141 pip3.exe

Rene Dudfield said...

Yeah, python 3.6 installs it by default. Which is great, and another reason why it's good to tell people to use python 3.6.

However, on windows it's not put on PATH by default. Which is why people link to pages like this "Help, I don't know how to install something with pip"
https://github.com/lawsie/guizero
http://catcatcode.com/blog/installing-python-packages-with-pip/

I'm not sure why pip and python aren't put on the windows PATH by default. I guess there must be a reason, but the choice not to harms newbies, and those trying to teach.

I promise I'm not making this stuff up. When people say, "pip doesn't exist", there might be a reason for them saying that other than them making stuff up. This is why I choose to listen to them and try to find out the reasons why they are getting error messages.