Today's article is another PIP article...

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
11,887
Reaction score
10,468
Credits
98,312
If you're going to use Python packages installed by PIP, you should keep them updated.

It's a simple enough process. It's a simple enough article.


PIP is pretty neat stuff.
 


That story has a bit of a tail.

If you use pip packages to manage your own app, you commonly do sth like pip freeze > requirements.txt to keep the versions locked. If you update the versions, your app might break.

It is possible but uncommon to install pip packages outside of venv or pyenv, because different apps come with different versions of dependencies (requirements.txt).

Most often pip is used (if you dont code in py yourself), when you download something from github thats written in py. In this case you shouldnt use your system's pip (as in pip without venv or pyenv). with those apps, you install the required pip packages via pip3 install -r requirements.txt, and to upgrade them you run git pull; pip3 install -r requirements.txt inside the git repo of the app you use.

When you install pip packages system wide, then your approach is ok, and you should most likely setup a cronjob (or systemd timer) to do that for you.

As for upgrade all, even without a venv or pyenv, this would be a way to go too:

Code:
pip freeze > requirements.txt
pip install -r requirements.txt --upgrade
 
It is possible but uncommon to install pip packages outside of venv or pyenv, because different apps come with different versions of dependencies (requirements.txt).
And if you use pip to upgrade system python modules it can also cause conflicts because there are packages with specific versions already installed through your the installation normal package manager.
 
Does apt upgrade also upgrade pip packages at times?
For example, you have the following package installed by the yum.
Code:
]# rpm -qa | grep python3-crypt
python3-cryptography-36.0.1-4.el9.x86_64
When you then try to install the same packages with pip, you get this.
Code:
]#  pip install --upgrade cryptography
Requirement already satisfied: cryptography in /usr/lib64/python3.9/site-packages (36.0.1)
Collecting cryptography
  Downloading cryptography-42.0.5-cp39-abi3-manylinux_2_28_x86_64.whl (4.6 MB)
     |████████████████████████████████| 4.6 MB 5.1 MB/s
Requirement already satisfied: cffi>=1.12 in /usr/lib64/python3.9/site-packages (from cryptography) (1.14.5)
Requirement already satisfied: pycparser in /usr/lib/python3.9/site-packages (from cffi>=1.12->cryptography) (2.20)
Requirement already satisfied: ply==3.11 in /usr/lib/python3.9/site-packages (from pycparser->cffi>=1.12->cryptography) (3.11)
Installing collected packages: cryptography
Successfully installed cryptography-42.0.5
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[root@ts-el9 ~]# rpm -qa | grep python3-crypt
python3-cryptography-36.0.1-4.el9.x86_64
Does apt upgrade also upgrade pip packages at times?
So the general rule is not to use pip to upgrade python modules already installed by your system's package manager. And even pip advises against it but instead advises you to install it in a virtual env.
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
It's not a problem when you run pip as a normal user because then the python modules installed by pip are installed in the home directory of that user.
 
So the general rule is not to use pip to upgrade python modules already installed by your system's package manager.

That'd be good information to add! I'll do so momentarily.

It's not a problem when you run pip as a normal user because then the python modules installed by pip are installed in the home directory of that user.

If you follow my instructions, you're doing that.
 
If you follow my instructions, you're doing that.
I do see it now, I missed the $ this morning. Might be good to add a section or line to not use pip as root.
 
I do see it now, I missed the $ this morning. Might be good to add a section or line to not use pip as root.

Maybe... The installation instructions are pretty clear and I'm pretty sure I specified that you aren't supposed to use root with PIP. The second installation article has you adding the path to your profile.

I suppose nobody is going to actually read those articles and I should make sure they know this.
 

Members online


Top