Skip to content

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).

88 points43 comments
Open on Reddit
About this post
Posted
Archived
Score
88 · 100% up
Kind
Text
ID
770fch

Author

14
posts
263
comments
3
media
View profile

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 --user flag.

68 points

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 --user flag. create an AUR package

36 points

If you're a normal user and not a python coder, then yes, an AUR package is preferable to using pip.

19 points

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.

8 points

You can also use the system site packages flag to use global packages.

1 points

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 A once and the problem should be fixed. I had to do this many times, especially with numpy.

Virtualenvs prevent this problem.

5 points

Don't forget that pip uninstall A does not remove dependencies and you should manually check it and remove them after with pip freeze

3 points

I'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)?

2 points

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 PATH variable. If you want it to appear in your menu then you'll need to add an entry for it.

4 points

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. :)

33 points

This is the answer. One env the each project. I use conda but the result is mostly the same.

7 points

What about Ruby gems? Pacman or gem install?

edit: Why the downvotes? What did I do?

8 points

The principles are the same:

  1. Install with pacman whenever possible.

  2. Try not to touch gem unless you are a ruby developer writing ruby code and you need a particular version of some dependency that isn't available with pacman. gem is not for normal users.

  3. Even then, don't let gem make any changes to the /usr directory. I don't know if ruby has the equivalent of a virtual environment or the --user flag, but it should and you should use them.

9 points

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.

2 points

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...

2 points

Oh so that's why I get those conflict errors. I'm understanding.

  1. Is there a method to index pip modules?
3 points
unknown author

Deleted before we saved it.

1 points

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.

3 points

Global OS dependencies for scripting languages are cancer.

2 points

You should understand what you're doing:

  1. pacman -S pip-module = pip module installed system-wide

  2. #root/sudo pip install pip-module = bad way of doing things

  3. @user (virtualenv) pip install pip-module = this is preferable, it keeps your python project separate from OS modules and your OS clean

2 points

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?

1 points

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.

Most likely you didn't use sudo and it complained that it couldn't write the files to the global directories.

Should I go learn about virtualenv?

If you do any python programming, yes, absolutely.

2 points

Do the same rules apply to conda? Or is anaconda isolated from the system files?

1 points

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.

0 points

WTF ? why are you downvoted, you are basically giving the good advice here.

1 points

:) Who knows. Arch users don't want to believe they don't know everything I guess.

1 points

Yep, this is the right advice. It is beyond me why Arch Wiki doesn't have it.

1 points

How fucking numb are you to even try that?

  • For one, logic should tell you "those are different programs, one doesn't necessarily know of the other"
  • Two it says so right here.
  • Three, python has a lot of versioned dependencies, and anything you install will most likely break which is the whole reason that venvs even exist.

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).

-33 points

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...

10 points

Eh. Don't listen to that spoilsport! Although you are a sysadmin now. Enjoy your new-found powers!

3 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.