LPT: Install Python modules using pacman instead of pip
pacman does not index pip modules, so if some python module is needed as a dependency for an app you'll get errors that file exist and you won't be able to install it untill you resolve the errors. (even with --force param).
About this post
- Posted
- Archived
- Score
- 88 · 100% up
- Kind
- Text
- ID
- 770fch
44 comments
Yup. Running
sudo pip install <stuff>will break your system. You should never make any changes to/usr, except through pacman. Pacman "owns"/usr, not you.If you need to install stuff with pip (perhaps because the thing you want isn't in the repos) then you should do it in a venv, or invoke pip with the
--userflag.If you're a normal user and not a python coder, then yes, an AUR package is preferable to using pip.
I would say you should use virtualenv instead for user applications. Yes, it may mean some packages get duplicated, but it will keep your environment clean.
You can also use the system site packages flag to use global packages.
Be careful with
pip install --user. It can install the package and missing dependencies with a higher priority than system packages, so system upgrades can break because Python first looks for user-installed package versions.So if you notice that your Python uses package A version x although Pacman tells you you have A version y, run
pip uninstall Aonce and the problem should be fixed. I had to do this many times, especially with numpy.Virtualenvs prevent this problem.
Don't forget that
pip uninstall Adoes not remove dependencies and you should manually check it and remove them after withpip freezeI've already been doing that with the Python packages I use, but what about running them? I mean, all pkgs I install using the --user parameter go into ~/.local/bin. How am I supposed to run them without having to open a terminal (since I noticed I'm not able to just run it the way I do with other non Python installed applications)?
Another question is about upgrading pkgs. I've googled a couple of solutions but none seemed to work properly. Is there an effective way of upgrading all packages at once (something Pacman style)?
If it's the kind of program that you run directly then that application shouldn't really be distributed with pip in the first place. Pip is for python libraries and tools, not for applications. Some developers will write an application intended to be used by people who don't know python but then they tell them to install it with pip; that's stupid and they should stop. Prefer pacman over pip wherever possible.
Pip isn't a system package manager. It's not for maintaining a single installation over a long time. You typically create a virtual environment for a specific purpose and then blow it away when you no longer need it. Pip is not designed for updating everything at once because (1) you shouldn't have very much installed in a given environment, and (2) careless updating will likely break the code that you're working on.
That said, what exactly do you mean by "running"? If you don't want to type the whole path then make sure that directory is in your
PATHvariable. If you want it to appear in your menu then you'll need to add an entry for it.If you're doing development, you should install modules (using pip) in a virtualenv. If you're installing a global app, it makes sense to install the dependencies globally using pacman, but that should be handled automatically by the packaging. And if you're installing an app without Pacman tracking it, you shouldn't do that. :)
This is the answer. One env the each project. I use conda but the result is mostly the same.
For those who've already made the mistake of doing
sudo pip install, I wrote a guide previously for this subreddit on how to fix your system and start doing things the right way: https://www.reddit.com/r/archlinux/comments/6vv5ty/guide_how_to_quit_using_pip_to_install_stuff/+1
https://aur.archlinux.org/packages/pip2pkgbuild/
What about Ruby gems? Pacman or gem install?
edit: Why the downvotes? What did I do?
The principles are the same:
Install with pacman whenever possible.
Try not to touch
gemunless you are a ruby developer writing ruby code and you need a particular version of some dependency that isn't available with pacman.gemis not for normal users.Even then, don't let
gemmake any changes to the/usrdirectory. I don't know if ruby has the equivalent of a virtual environment or the--userflag, but it should and you should use them.It has user and bundler
Most Ruby devs will use RVM or rbenv which keeps Ruby out of the system and keeps it in the home directory. No sudo required.
I'm not familiar with Ruby but I imagine installing via gem would cause the same problems as using pip. If you install something without using pacman, it won't be able to track that package, which can get funky. Not sure why you're being downvoted, seems like a valid question...
Thanks for the reply!
Oh so that's why I get those conflict errors. I'm understanding.
Deleted before we saved it.
There are so many different platforms that have their own package management...I really feel there should be a generalized solution for pacman to maintain ownership of those packages and files.
$ pip list | wc -l
...
87
oh boy....
Some of those are managed by pacman though, IIRC. Pip might list them as well.
Yeah, pip indexes the modules installed with pacman
Global OS dependencies for scripting languages are cancer.
You should understand what you're doing:
pacman -S pip-module = pip module installed system-wide
#root/sudo pip install pip-module = bad way of doing things
@user (virtualenv) pip install pip-module = this is preferable, it keeps your python project separate from OS modules and your OS clean
Every time I've tried to install anything with pip at all, I wind up getting a python exception and a crash of pip. Same with easy_install. I've also never used a virtual environment for my development. So I've always gone with pacman. If that didn't work, then I download the source and throw it in my app directory. (I do not code professionally and almost never release code publicly)
Is there maybe something I'm messing up when using pip/easy_install? Should I go learn about virtualenv?
Most likely you didn't use sudo and it complained that it couldn't write the files to the global directories.
If you do any python programming, yes, absolutely.
Right on. Thanks!
Do the same rules apply to conda? Or is anaconda isolated from the system files?
This is bad advice. The only reason you want to install packages into the system python installation is if an application installed with pacman needs it, and if that is the case then pacman will pull it down as a dependency anyway.
If you are doing development you should be installing into a virtualenv and then using pip.
WTF ? why are you downvoted, you are basically giving the good advice here.
:) Who knows. Arch users don't want to believe they don't know everything I guess.
Yep, this is the right advice. It is beyond me why Arch Wiki doesn't have it.
How fucking numb are you to even try that?
In conclusion, this isn't an LPT, it's common sense for sys-admins.
Or rather, it should be. I work at an MSP and had to deal with "why is ansible so old on debian?" (ansible is python-software, and everyone at this company has extensible sys-admin knowledge. Even the salesmen).
I'm not a sys-admin, I'm just the one from a thousands that moved from Windows to Linux.
I've installed Arch Linux 2 weeks ago and just sharing my observations.
I'm sorry if they are dumb...
Eh. Don't listen to that spoilsport! Although you are a sysadmin now. Enjoy your new-found powers!