Which package manager do you use?
2024 Python package manager overview - Packaging - Discussions on Python.org
How do I get a list of locally installed Python modules? - Stack Overflow
installation - How to list all installed packages and their versions in Python? - Stack Overflow
Videos
there are 3 popular package managers for python modules being used the most frequently: conda pip apt(for debian-based linux).
I initially installed anaconda which gave me conda but together with a lot of extra package bloat I may never use.
So naturally I tried miniconda. It turns out there are caveats to this too:
conda-forge is touted as a robust channel but when i tried installing all my most used packages from the conda-forge channel here is what I got:
-
python3.10 as of writing -
pandas1.3.4 (latest) -
scikit-learn(latest) -
jupyterlab(no problem) -
matplotlib(CANNOT INSTALL. dependency conflict with python version on conda-forge) -
requests(CANNOT INSTALL. dependency conflict with python version on conda-forge)
I tried conda package manager with the defaults channel:
-
all the packages install but
pythonfrom defaults channel is 3.9.7. Everything works with this but no python==3.10.
When I made a separate virtual environment and tried installing via pip package manager only:
-
everything worked.
python--version is 3.10. every package installed to the latest version EXCEPTscikit-learnwhich is not installing for some reason.
And then there's apt which manages all other non-python packages on my linux and has a few python packages on ubuntu's repositories. But apt does not install packages in virtual environment and may not contain as many packages as pip or conda.
it appears conda with defaults channel is the most robust of all. I don't want to use multiple package managers as it is a hassle when updating and may lead to dependency hell. I want to know which package managers are being used the most considering they are hassle-free and easy to update and keep track of.
So what package manager do you use?
ยป pip install meta-package-manager
help('modules')
in a Python shell/prompt.
Solution
Do not use with pip > 10.0!
My 50 cents for getting a pip freeze-like list from a Python script:
import pip
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
print(installed_packages_list)
As a (too long) one liner:
sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()])
Giving:
['behave==1.2.4', 'enum34==1.0', 'flask==0.10.1', 'itsdangerous==0.24',
'jinja2==2.7.2', 'jsonschema==2.3.0', 'markupsafe==0.23', 'nose==1.3.3',
'parse-type==0.3.4', 'parse==1.6.4', 'prettytable==0.7.2', 'requests==2.3.0',
'six==1.6.1', 'vioozer-metadata==0.1', 'vioozer-users-server==0.1',
'werkzeug==0.9.4']
Scope
This solution applies to the system scope or to a virtual environment scope, and covers packages installed by setuptools, pip and (god forbid) easy_install.
My use case
I added the result of this call to my Flask server, so when I call it with http://example.com/exampleServer/environment I get the list of packages installed on the server's virtualenv. It makes debugging a whole lot easier.
Caveats
I have noticed a strange behaviour of this technique - when the Python interpreter is invoked in the same directory as a setup.py file, it does not list the package installed by setup.py.
Steps to reproduce:
Create a virtual environment
$ cd /tmp
$ virtualenv test_env
New python executable in test_env/bin/python
Installing setuptools, pip...done.
$ source test_env/bin/activate
(test_env) $
Clone a Git repository with setup.py
(test_env) $ git clone https://github.com/behave/behave.git
Cloning into 'behave'...
remote: Reusing existing pack: 4350, done.
remote: Total 4350 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (4350/4350), 1.85 MiB | 418.00 KiB/s, done.
Resolving deltas: 100% (2388/2388), done.
Checking connectivity... done.
We have behave's setup.py in /tmp/behave:
(test_env) $ ls /tmp/behave/setup.py
/tmp/behave/setup.py
Install the Python package from the Git repository
(test_env) $ cd /tmp/behave && pip install .
running install
...
Installed /private/tmp/test_env/lib/python2.7/site-packages/enum34-1.0-py2.7.egg
Finished processing dependencies for behave==1.2.5a1
If we run the aforementioned solution from /tmp
>>> import pip
>>> sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()])
['behave==1.2.5a1', 'enum34==1.0', 'parse-type==0.3.4', 'parse==1.6.4', 'six==1.6.1']
>>> import os
>>> os.getcwd()
'/private/tmp'
If we run the aforementioned solution from /tmp/behave
>>> import pip
>>> sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()])
['enum34==1.0', 'parse-type==0.3.4', 'parse==1.6.4', 'six==1.6.1']
>>> import os
>>> os.getcwd()
'/private/tmp/behave'
behave==1.2.5a1 is missing from the second example, because the working directory contains behave's setup.py file.
I could not find any reference to this issue in the documentation. Perhaps I shall open a bug for it.
If you have pip install and you want to see what packages have been installed with your installer tools you can simply call this:
pip freeze
It will also include version numbers for the installed packages.
Update
pip has been updated to also produce the same output as pip freeze by calling:
pip list
Note
The output from pip list is formatted differently, so if you have some shell script that parses the output (maybe to grab the version number) of freeze and want to change your script to call list, you'll need to change your parsing code.
help('modules') should do it for you.
in IPython :
In [1]: import #import press-TAB
Display all 631 possibilities? (y or n)
ANSI audiodev markupbase
AptUrl audioop markupsafe
ArgImagePlugin avahi marshal
BaseHTTPServer axi math
Bastion base64 md5
BdfFontFile bdb mhlib
BmpImagePlugin binascii mimetools
BufrStubImagePlugin binhex mimetypes
CDDB bisect mimify
CDROM bonobo mmap
CGIHTTPServer brlapi mmkeys
Canvas bsddb modulefinder
CommandNotFound butterfly multifile
ConfigParser bz2 multiprocessing
ContainerIO cPickle musicbrainz2
Cookie cProfile mutagen
Crypto cStringIO mutex
CurImagePlugin cairo mx
DLFCN calendar netrc
DcxImagePlugin cdrom new
Dialog cgi nis
DiscID cgitb nntplib
DistUpgrade checkbox ntpath