Install ROS Kinetic on MacOS under a separate Anaconda environment - python

I'm installing ROS Kinetic on MacOS Sierra 10.12.6 under a seperate environment under Python Anaconda distribution.
Here is my python version(my seperate python environment in Anaconda is called "ros-kinetic"):
(ros-kinetic) jizhe#jizhedeMacBook-Pro  ~/ros_catkin_ws  python --version
Python 3.6.4 :: Anaconda, Inc.
I followed the guide: http://wiki.ros.org/kinetic/Installation/OSX/Homebrew/Source.
When I execute the "rosdep install" command, I got the following error:
(ros-kinetic) jizhe#jizhedeMacBook-Pro ~/ros_catkin_ws  rosdep install --from-paths src --ignore-src --rosdistro kinetic -y
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
actionlib: No definition of [python-wxtools] for OS [osx]
catkin: No definition of [google-mock] for OS [osx]
roslisp: No definition of [google-mock] for OS [osx]
Obviously, there is something wrong with the package "python-wxtools" and "google-mock".
I've already install the wxpython via "brew install wxpython", and here is the wxpython info:
(ros-kinetic) jizhe#jizhedeMacBook-Pro  ~/ros_catkin_ws  brew info wxpython
wxpython: stable 3.0.2.0 (bottled)
Python bindings for wxWidgets
https://www.wxwidgets.org/
/usr/local/Cellar/wxpython/3.0.2.0_1 (1,108 files, 37.9MB) *
Poured from bottle on 2018-02-24 at 03:56:21
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/wxpython.rb
==> Dependencies
Required: wxmac ✔
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/jizhe/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/jizhe/Library/Python/2.7/lib/python/site-packages/homebrew.pth
And I've already run the command:
$ mkdir -p ~/Library/Python/2.7/lib/python/site-packages
$ echo "$(brew --prefix)/lib/python2.7/site-packages" >> ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
So, what's wrong with the package "google-mock" and "python-wxtools", how can I solve this problem?

Try installing with --skip-keys python-wxtools --skip-keys google-mock. It worked for me.

There is a ticket for this issue. Basically the workaround is to install googletest manually. Not sure what's wrong with python-wxtools.
edit: If you're using ros-install-osx, you can add the following lines to your rosdeps.yaml file:
google-mock:
osx:
homebrew:
packages: []

I found this question from a Google search, just for your information in 2021 installing ROS in conda also on macOS should be much straightforward, see the following links:
https://medium.com/robostack/cross-platform-conda-packages-for-ros-fa1974fd1de3
https://github.com/RoboStack/ros-noetic

Related

How to install GDAL Python Bindings for Postgres.app

I installed the latest Postgre.app version Version 2.5.6 (139) Universal version for my new MacBook Pro M1. After setting up the CLI tools, I am able to access all gdal binaries that come bundled like gdalinfo.
However I also need to install the python bindings to use cli utilities like gdal2tiles.py. What's the right way to go about installing these so they work with the rest of gdal bundled with latest Postgress.app?
Current version bundled with Postgres.app is
➜ gdalinfo --version
GDAL 3.3.3, released 2021/10/25
Postgres.app installs GDAL binaries at:
/Applications/Postgres.app/Contents/Versions/latest/bin and currently has the following bundled:
clusterdb ecpg gdal_translate gdalinfo gdaltindex invproj pg_amcheck pg_ctl pg_resetwal pg_verifybackup proj vacuumdb
createdb gdal-config gdal_viewshed gdallocationinfo gdaltransform nearblack pg_archivecleanup pg_dump pg_restore pg_waldump psql vacuumlo
createuser gdal_contour gdaladdo gdalmanage gdalwarp ogr2ogr pg_basebackup pg_dumpall pg_rewind pgbench raster2pgsql
cs2cs gdal_create gdalbuildvrt gdalmdiminfo geod ogrinfo pg_checksums pg_isready pg_test_fsync pgsql2shp reindexdb
dropdb gdal_grid gdaldem gdalmdimtranslate initdb ogrtindex pg_config pg_receivewal pg_test_timing postgres shp2pgsql
dropuser gdal_rasterize gdalenhance gdalsrsinfo invgeod oid2name pg_controldata pg_recvlogical pg_upgrade postmaster testepsg
I realize there are plenty of ways to install gdal with python bindings using brew and pip, but I am looking to do this the right way while utilizing the core gdal that comes with Postgres.app
Any help is appreciated, Thanks!
Use pygdal, it is made for this exact purpose.
export GDALHOME="/Applications/Postgres.app/Contents/Versions/latest"
pip install pygdal=="`gdal-config --version`.*"

How to resolve CMake Error: Could not find a package configuration file provided by "boost_python3"

I tried to install the lanelet2 library according to the github installation guide at https://github.com/fzi-forschungszentrum-informatik/Lanelet2.
When I perform catkin build I get the following error:
Errors << lanelet2_python:cmake /home/student/catkin_ws/logs/lanelet2_python/build.cmake.000.log
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake:117 (find_package):
Could not find a package configuration file provided by "boost_python3"
(requested version 1.71.0) with any of the following names:
boost_python3Config.cmake
boost_python3-config.cmake
Add the installation prefix of "boost_python3" to CMAKE_PREFIX_PATH or set
"boost_python3_DIR" to a directory containing one of the above files. If
"boost_python3" provides a separate development package or SDK, be sure it
has been installed.
My OS is Ubuntu 20.04 with ROS noetic. The build is performed inside a venv with Python Version 3.8.10.
The command python is pointing to python3. I've also installed the following dependencies:
sudo apt-get install ros-noetic-rospack ros-noetic-catkin ros-noetic-mrt-cmake-modules
sudo apt-get install libboost-dev libeigen3-dev libgeographic-dev libpugixml-dev libpython3-dev libboost-python-dev python3-catkin-tools
Does someone have an idea how to resolve this error?
See neutrinoyu's comment at https://github.com/ethz-asl/kalibr/issues/368#issuecomment-651726289
/kalibr/Schweizer-Messer/numpy_eigen/cmake/add_python_export_library.cmake:89
change
list(APPEND BOOST_COMPONENTS python3)
to
list(APPEND BOOST_COMPONENTS python)

How do I check all pip packages for packages installed globally using sudo? [duplicate]

Is there a way in Python to list all installed packages and their versions?
I know I can go inside python/Lib/site-packages and see what files and directories exist, but I find this very awkward. What I'm looking for something that is similar to npm list i.e. npm-ls.
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
If you want to get information about your installed python distributions and don't want to use your cmd console or terminal for it, but rather through python code, you can use the following code (tested with python 3.4):
import pip #needed to use the pip functions
for i in pip.get_installed_distributions(local_only=True):
print(i)
The pip.get_installed_distributions(local_only=True) function-call returns an iterable and because of the for-loop and the print function the elements contained in the iterable are printed out separated by new line characters (\n).
The result will (depending on your installed distributions) look something like this:
cycler 0.9.0
decorator 4.0.4
ipykernel 4.1.0
ipython 4.0.0
ipython-genutils 0.1.0
ipywidgets 4.0.3
Jinja2 2.8
jsonschema 2.5.1
jupyter 1.0.0
jupyter-client 4.1.1
#... and so on...
To run this in later versions of pip (tested on pip==10.0.1) use the following:
from pip._internal.operations.freeze import freeze
for requirement in freeze(local_only=True):
print(requirement)
My take:
#!/usr/bin/env python3
import pkg_resources
dists = [str(d).replace(" ","==") for d in pkg_resources.working_set]
for i in dists:
print(i)
from command line
python -c help('modules')
can be used to view all modules, and for specific modules
python -c help('os')
For Linux below will work
python -c "help('os')"
For easy_install (deprecated, Python <= v2.7, do not use this, use pip instead; use this only in old projects that still use easy_install)
You can try : Yolk
For install yolk, try:
easy_install yolk
Yolk is a Python tool for obtaining information about installed Python
packages and querying packages avilable on PyPI (Python Package
Index).
You can see which packages are active, non-active or in development
mode and show you which have newer versions available by querying
PyPI.
yes! you should be using pip as your python package manager ( http://pypi.python.org/pypi/pip )
with pip installed packages, you can do a
pip freeze
and it will list all installed packages. You should probably also be using virtualenv and virtualenvwrapper. When you start a new project, you can do
mkvirtualenv my_new_project
and then (inside that virtualenv), do
pip install all_your_stuff
This way, you can workon my_new_project and then pip freeze to see which packages are installed for that virtualenv/project.
for example:
➜ ~ mkvirtualenv yo_dude
New python executable in yo_dude/bin/python
Installing setuptools............done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/get_env_details
(yo_dude)➜ ~ pip install django
Downloading/unpacking django
Downloading Django-1.4.1.tar.gz (7.7Mb): 7.7Mb downloaded
Running setup.py egg_info for package django
Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from 644 to 755
changing mode of /Users/aaylward/dev/virtualenvs/yo_dude/bin/django-admin.py to 755
Successfully installed django
Cleaning up...
(yo_dude)➜ ~ pip freeze
Django==1.4.1
wsgiref==0.1.2
(yo_dude)➜ ~
or if you have a python package with a requirements.pip file,
mkvirtualenv my_awesome_project
pip install -r requirements.pip
pip freeze
will do the trick
If you're using anaconda:
conda list
will do it! See: https://conda.io/docs/_downloads/conda-cheatsheet.pdf
Here's a way to do it using PYTHONPATH instead of the absolute path of your python libs dir:
for d in `echo "${PYTHONPATH}" | tr ':' '\n'`; do ls "${d}"; done
[ 10:43 Jonathan#MacBookPro-2 ~/xCode/Projects/Python for iOS/trunk/Python for iOS/Python for iOS ]$ for d in `echo "$PYTHONPATH" | tr ':' '\n'`; do ls "${d}"; done
libpython2.7.dylib pkgconfig python2.7
BaseHTTPServer.py _pyio.pyc cgitb.pyo doctest.pyo htmlentitydefs.pyc mimetools.pyc plat-mac runpy.py stringold.pyc traceback.pyo
BaseHTTPServer.pyc _pyio.pyo chunk.py dumbdbm.py htmlentitydefs.pyo mimetools.pyo platform.py runpy.pyc stringold.pyo tty.py
BaseHTTPServer.pyo _strptime.py chunk.pyc dumbdbm.pyc htmllib.py mimetypes.py platform.pyc runpy.pyo stringprep.py tty.pyc
Bastion.py _strptime.pyc chunk.pyo dumbdbm.pyo htmllib.pyc mimetypes.pyc platform.pyo sched.py stringprep.pyc tty.pyo
Bastion.pyc _strptime.pyo cmd.py
....
for using code, for example to check what modules in Hackerrank etc :
import os
os.system("pip list")
If this is needed to run from within python you can just invoke subprocess
from subprocess import PIPE, Popen
pip_process = Popen(["pip freeze"], stdout=PIPE,
stderr=PIPE, shell=True)
stdout, stderr = pip_process.communicate()
print(stdout.decode("utf-8"))
For Windows 10, I think this is what you are looking for a list of available installed Pythons. This is different from a list of packages as you can see below. Also, on Ubuntu 20.04, I think the command is Python3 -0 list.
Yes, this works similar to node version manager.
c:\Users\user\AppData\Local\Programs\Python>py -0 list
Python 0 not found!
Installed Pythons found by py Launcher for Windows
-3.10-64 *
-3.9-64
-3.7-64
-3.6-64
-2.7-64
Requested Python version (0) not installed, use -0 for available pythons
c:\Users\user\AppData\Local\Programs\Python>py -0p
Installed Pythons found by py Launcher for Windows
-3.10-64 C:\Python310\python.exe *
-3.9-64 C:\Users\user\AppData\Local\Programs\Python\Python39\python.exe
-3.7-64 C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe
-3.6-64 C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe
-2.7-64 C:\Python27amd64\python.exe
See: https://www.infoworld.com/article/3617292/how-to-use-pythons-py-launcher-for-windows.html
See Also: https://www.freecodecamp.org/news/manage-multiple-python-versions-and-virtual-environments-venv-pyenv-pyvenv-a29fb00c296f/
From the above link, "If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and switch between versions. This is not to be confused with the previously mentioned depreciated pyvenv script. It does not come bundled with Python and must be installed separately." -- Note: This acts similar to Node Version Manager with versions of Node.js and NPM.
See Also: https://github.com/pyenv-win/pyenv-win#installation
Action: Open PowerShell and type the following web request. The link above offers other approaches as well, but this appears to be the easiest approach. The name of the runtime output file is not a name variant like 'pyenv-win' but actually 'pyenv', as originally expected.
PS C:\Users\user> Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"
pyenv-win 2.64.11 installed.
No updates available.
PS C:\Users\user>
Example Output for working with 'pyenv', Python's Version Manager.
C:\Users\user>pyenv --version
pyenv 2.64.11
C:\Users\name>pyenv
pyenv 2.64.11
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
duplicate Creates a duplicate python environment
local Set or show the local application-specific Python version
global Set or show the global Python version
shell Set or show the shell-specific Python version
install Install a Python version using python-build
uninstall Uninstall a specific Python version
update Update the cached version DB
rehash Rehash pyenv shims (run this after installing executables)
vname Show the current Python version
version Show the current Python version and its origin
version-name Show the current Python version
versions List all Python versions available to pyenv
exec Runs an executable by first preparing PATH so that the selected Python
which Display the full path to an executable
whence List all Python versions that contain the given executable
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv-win/pyenv-win#readme
C:\Users\name>pyenv commands
--version
commands
duplicate
exec
export
global
help
install
local
rehash
shell
shims
uninstall
update
version-name
version
versions
vname
whence
which
C:\Users\name>pyenv version
No global python version has been set yet. Please set the global version by typing:
pyenv global 3.7.2
C:\Users\user>pyenv local
no local version configured for this directory
C:\Users\user>pyenv global
no global version configured
C:\Users\user>pyenv local 3.9-64
pyenv specific python requisite didn't meet. Project is using different version of python.
Install python '3.9-64' by typing: 'pyenv install 3.9-64'
My Note: Version name from 'https://www.python.org/downloads/' is different to those provided by 'pyenv'. This version was already installed locally, but it is outside the control of this Python version manager, so it is not visible to the manager.
C:\Users\user>pyenv install 3.8.10-64
:: [Info] :: Mirror: https://www.python.org/ftp/python
pyenv-install: definition not found: local
My Note(s): This Python version is not part of the managed list although this version exists at 'https://www.python.org/downloads/'. So you must see the list provided by the manager. See all available versions with `pyenv install --list'.
C:\Users\user>pyenv install --list
Note: Review the list from this call and make your selection.
C:\Users\user>pyenv install 3.8.10
:: [Info] :: Mirror: https://www.python.org/ftp/python
:: [Downloading] :: 3.8.10 ...
:: [Downloading] :: From https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64-webinstall.exe
:: [Downloading] :: To C:\Users\user\.pyenv\pyenv-win\install_cache\python-3.8.10-amd64-webinstall.exe
:: [Installing] :: 3.8.10 ...
:: [Info] :: completed! 3.8.10
My Note(s): With this Python version manager, 'pyenv', following installation, it appears that one must designate the version as 'local' or 'global' after the installation which would follow the same paradigm as the Node.js Version Manager (NVM). Again, from what I can see, the Python version manager can only see what versions of Python the manager installs; and it can only uninstall a version it has installed with the Python version manager.
C:\Users\user>pyenv local 3.8.10
C:\Users\user>pyenv local
3.8.10
C:\Users\user>pyenv version
3.8.10 (set by C:\Users\user\.python-version)
C:\Users\user>pyenv versions
* 3.8.10 (set by C:\Users\user\.python-version)
C:\Users\user>pyenv vname
3.8.10
C:\Users\user>pyenv global
no global version configured
The following below is for working with packages.
See Also: https://www.freecodecamp.org/news/manage-multiple-python-versions-and-virtual-environments-venv-pyenv-pyvenv-a29fb00c296f/
From the above link, "When the environment is active, any packages can be installed to it via pip as normal. By default, the newly created environment will not include any packages already installed on the machine. As pip itself will not necessarily be installed on the machine. It is recommended to first upgrade pip to the latest version, using 'pip install --upgrade pip'." -- I performed the pip upgrade just before making these two calls to list the packages and their versions below.
c:\Users\user\AppData\Local\Programs\Python>pip list
Package Version
---------- -------
pip 22.1
setuptools 62.2.0
wheel 0.37.1
c:\Users\user\AppData\Local\Programs\Python>pip list --local
Package Version
---------- -------
pip 22.1
setuptools 62.2.0
wheel 0.37.1

nrfutil - "ImportError: No module named main" on Nixos

I'm using the tool nrfutil which is implemented in Python. To be able to use it under NixOS I was using a default.nix file, that installed nrfutil into a venv. This worked for some time very well. (The last build on the build server using Nix within an alpine container could build the software I'm working on 11 days ago successfully.) When I do exactly the same things (i.e. restarting the CI server build without changes), the build fails now complaining about pip being incorrect:
$ nix-shell
New python executable in /home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7
Not overwriting existing python script /home/matthias/source/tbconnect/bootloader/.venv/bin/python (you must use /home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7)
Installing pip, wheel...
done.
Traceback (most recent call last):
File "/home/matthias/source/tbconnect/bootloader/.venv/bin/pip", line 6, in <module>
from pip._internal.main import main
ImportError: No module named main
To me it seems that the module main should exist:
$ ls -l .venv/lib/python2.7/site-packages/pip/_internal/main.py
-rw-r--r-- 1 matthias matthias 1359 10月 15 12:27 .venv/lib/python2.7/site-packages/pip/_internal/main.py
I'm not very much into the Python environment, so I don't know any further. Has somebody any pointer for me where to continue debugging? How is Python resolving modules? Why doesn't it find the module, that seems to be present to me?
This is my default.nix that I use to install pip:
with import <nixpkgs> {};
with pkgs.python27Packages;
stdenv.mkDerivation {
name = "impurePythonEnv";
buildInputs = [
automake
autoconf
gcc-arm-embedded-7
# these packages are required for virtualenv and pip to work:
#
python27Full
python27Packages.virtualenv
python27Packages.pip
# the following packages are related to the dependencies of your python
# project.
# In this particular example the python modules listed in the
# requirements.txt require the following packages to be installed locally
# in order to compile any binary extensions they may require.
#
taglib
openssl
git
stdenv
zlib ];
src = null;
shellHook = ''
# set SOURCE_DATE_EPOCH so that we can use python wheels
SOURCE_DATE_EPOCH=$(date +%s)
virtualenv --no-setuptools .venv
export PATH=$PWD/.venv/bin:$PATH
#pip install nrfutil
pip help
# the following is required to build micro_ecc_lib_nrf52.a in the SDK
export GNU_INSTALL_ROOT="${gcc-arm-embedded-7}/bin/"
unset CC
'';
}
I replaced pip install nrfutil with pip help to make sure the problem is not the package I try to install itself.
I'm still using python 2.7 as the nrfutil still is not fit for Python 3.
Anyway replacing python27 with python37 did not change the error I get when trying to start pip.)
NixOS version used locally is 19.09. Nix in the CI docker container is nixos/nix:latest which is the nix package manager on Alpine Linux.
Update:
Actually it works when I replace the call to pip install nrfutil with python2.7 -m pip install nrfutil. This actually confuses me even more. python2.7 is exactly the binary that is in the shebang of pip:
[nix-shell:~/source/tbconnect/bootloader]$ type python2.7
python2.7 is /home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7
[nix-shell:~/source/tbconnect/bootloader]$ type pip
pip is /home/matthias/source/tbconnect/bootloader/.venv/bin/pip
[nix-shell:~/source/tbconnect/bootloader]$ head --lines 2 .venv/bin/pip
#!/home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7
# -*- coding: utf-8 -*-
Update 2:
I found out that another way to fix the problem is to edit .venv/bin/pip. This script tried the following import:
from pip._internal.main import main
Which I think is the new module path starting with pip 19.3. But I still have pip 19.2. When I change this line to:
from pip._internal import main
Running pip by typing pip is working.
The thing is I have no idea why the pip script is trying to load the new module path while NixOS still has the old version of pip.
I also opened an issue for NixOS on GitHub: https://github.com/NixOS/nixpkgs/issues/71178
I got your shell derivation to work by dropping the Python27Packages.pip,
(nix-shell) 2d [azul:/tmp/lixo12333] $
>>> pip list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Package Version
---------------- -------
behave 1.2.6
Click 7.0
crcmod 1.7
ecdsa 0.13.3
enum34 1.1.6
future 0.18.2
intelhex 2.2.1
ipaddress 1.0.23
libusb1 1.7.1
linecache2 1.0.0
nrfutil 5.2.0
parse 1.12.1
parse-type 0.5.2
pc-ble-driver-py 0.11.4
piccata 1.0.1
pip 19.3.1
protobuf 3.10.0
pyserial 3.4
pyspinel 1.0.0a3
PyYAML 4.2b4
setuptools 41.6.0
six 1.12.0
tqdm 4.37.0
traceback2 1.4.0
virtualenv 16.4.3
wheel 0.33.6
wrapt 1.11.2
(nix-shell) 2d [azul:/tmp/lixo12333] $
and my default.nix
with import <nixpkgs> {};
with pkgs.python27Packages;
stdenv.mkDerivation {
name = "impurePythonEnv";
buildInputs = [
automake
autoconf
gcc-arm-embedded-7
# these packages are required for virtualenv and pip to work:
#
python27Full
python27Packages.virtualenv
# the following packages are related to the dependencies of your python
# project.
# In this particular example the python modules listed in the
# requirements.txt require the following packages to be installed locally
# in order to compile any binary extensions they may require.
#
taglib
openssl
git
stdenv
zlib ];
src = null;
shellHook = ''
# set SOURCE_DATE_EPOCH so that we can use python wheels
SOURCE_DATE_EPOCH=$(date +%s)
virtualenv .venv
export PATH=$PWD/.venv/bin:$PATH
pip install nrfutil
#pip help
# the following is required to build micro_ecc_lib_nrf52.a in the SDK
export GNU_INSTALL_ROOT="${gcc-arm-embedded-7}/bin/"
unset CC
'';
}

How to list all installed packages and their versions in Python?

Is there a way in Python to list all installed packages and their versions?
I know I can go inside python/Lib/site-packages and see what files and directories exist, but I find this very awkward. What I'm looking for something that is similar to npm list i.e. npm-ls.
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
If you want to get information about your installed python distributions and don't want to use your cmd console or terminal for it, but rather through python code, you can use the following code (tested with python 3.4):
import pip #needed to use the pip functions
for i in pip.get_installed_distributions(local_only=True):
print(i)
The pip.get_installed_distributions(local_only=True) function-call returns an iterable and because of the for-loop and the print function the elements contained in the iterable are printed out separated by new line characters (\n).
The result will (depending on your installed distributions) look something like this:
cycler 0.9.0
decorator 4.0.4
ipykernel 4.1.0
ipython 4.0.0
ipython-genutils 0.1.0
ipywidgets 4.0.3
Jinja2 2.8
jsonschema 2.5.1
jupyter 1.0.0
jupyter-client 4.1.1
#... and so on...
To run this in later versions of pip (tested on pip==10.0.1) use the following:
from pip._internal.operations.freeze import freeze
for requirement in freeze(local_only=True):
print(requirement)
My take:
#!/usr/bin/env python3
import pkg_resources
dists = [str(d).replace(" ","==") for d in pkg_resources.working_set]
for i in dists:
print(i)
from command line
python -c help('modules')
can be used to view all modules, and for specific modules
python -c help('os')
For Linux below will work
python -c "help('os')"
For easy_install (deprecated, Python <= v2.7, do not use this, use pip instead; use this only in old projects that still use easy_install)
You can try : Yolk
For install yolk, try:
easy_install yolk
Yolk is a Python tool for obtaining information about installed Python
packages and querying packages avilable on PyPI (Python Package
Index).
You can see which packages are active, non-active or in development
mode and show you which have newer versions available by querying
PyPI.
yes! you should be using pip as your python package manager ( http://pypi.python.org/pypi/pip )
with pip installed packages, you can do a
pip freeze
and it will list all installed packages. You should probably also be using virtualenv and virtualenvwrapper. When you start a new project, you can do
mkvirtualenv my_new_project
and then (inside that virtualenv), do
pip install all_your_stuff
This way, you can workon my_new_project and then pip freeze to see which packages are installed for that virtualenv/project.
for example:
➜ ~ mkvirtualenv yo_dude
New python executable in yo_dude/bin/python
Installing setuptools............done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/get_env_details
(yo_dude)➜ ~ pip install django
Downloading/unpacking django
Downloading Django-1.4.1.tar.gz (7.7Mb): 7.7Mb downloaded
Running setup.py egg_info for package django
Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from 644 to 755
changing mode of /Users/aaylward/dev/virtualenvs/yo_dude/bin/django-admin.py to 755
Successfully installed django
Cleaning up...
(yo_dude)➜ ~ pip freeze
Django==1.4.1
wsgiref==0.1.2
(yo_dude)➜ ~
or if you have a python package with a requirements.pip file,
mkvirtualenv my_awesome_project
pip install -r requirements.pip
pip freeze
will do the trick
If you're using anaconda:
conda list
will do it! See: https://conda.io/docs/_downloads/conda-cheatsheet.pdf
Here's a way to do it using PYTHONPATH instead of the absolute path of your python libs dir:
for d in `echo "${PYTHONPATH}" | tr ':' '\n'`; do ls "${d}"; done
[ 10:43 Jonathan#MacBookPro-2 ~/xCode/Projects/Python for iOS/trunk/Python for iOS/Python for iOS ]$ for d in `echo "$PYTHONPATH" | tr ':' '\n'`; do ls "${d}"; done
libpython2.7.dylib pkgconfig python2.7
BaseHTTPServer.py _pyio.pyc cgitb.pyo doctest.pyo htmlentitydefs.pyc mimetools.pyc plat-mac runpy.py stringold.pyc traceback.pyo
BaseHTTPServer.pyc _pyio.pyo chunk.py dumbdbm.py htmlentitydefs.pyo mimetools.pyo platform.py runpy.pyc stringold.pyo tty.py
BaseHTTPServer.pyo _strptime.py chunk.pyc dumbdbm.pyc htmllib.py mimetypes.py platform.pyc runpy.pyo stringprep.py tty.pyc
Bastion.py _strptime.pyc chunk.pyo dumbdbm.pyo htmllib.pyc mimetypes.pyc platform.pyo sched.py stringprep.pyc tty.pyo
Bastion.pyc _strptime.pyo cmd.py
....
for using code, for example to check what modules in Hackerrank etc :
import os
os.system("pip list")
If this is needed to run from within python you can just invoke subprocess
from subprocess import PIPE, Popen
pip_process = Popen(["pip freeze"], stdout=PIPE,
stderr=PIPE, shell=True)
stdout, stderr = pip_process.communicate()
print(stdout.decode("utf-8"))
For Windows 10, I think this is what you are looking for a list of available installed Pythons. This is different from a list of packages as you can see below. Also, on Ubuntu 20.04, I think the command is Python3 -0 list.
Yes, this works similar to node version manager.
c:\Users\user\AppData\Local\Programs\Python>py -0 list
Python 0 not found!
Installed Pythons found by py Launcher for Windows
-3.10-64 *
-3.9-64
-3.7-64
-3.6-64
-2.7-64
Requested Python version (0) not installed, use -0 for available pythons
c:\Users\user\AppData\Local\Programs\Python>py -0p
Installed Pythons found by py Launcher for Windows
-3.10-64 C:\Python310\python.exe *
-3.9-64 C:\Users\user\AppData\Local\Programs\Python\Python39\python.exe
-3.7-64 C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe
-3.6-64 C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe
-2.7-64 C:\Python27amd64\python.exe
See: https://www.infoworld.com/article/3617292/how-to-use-pythons-py-launcher-for-windows.html
See Also: https://www.freecodecamp.org/news/manage-multiple-python-versions-and-virtual-environments-venv-pyenv-pyvenv-a29fb00c296f/
From the above link, "If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and switch between versions. This is not to be confused with the previously mentioned depreciated pyvenv script. It does not come bundled with Python and must be installed separately." -- Note: This acts similar to Node Version Manager with versions of Node.js and NPM.
See Also: https://github.com/pyenv-win/pyenv-win#installation
Action: Open PowerShell and type the following web request. The link above offers other approaches as well, but this appears to be the easiest approach. The name of the runtime output file is not a name variant like 'pyenv-win' but actually 'pyenv', as originally expected.
PS C:\Users\user> Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"
pyenv-win 2.64.11 installed.
No updates available.
PS C:\Users\user>
Example Output for working with 'pyenv', Python's Version Manager.
C:\Users\user>pyenv --version
pyenv 2.64.11
C:\Users\name>pyenv
pyenv 2.64.11
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
duplicate Creates a duplicate python environment
local Set or show the local application-specific Python version
global Set or show the global Python version
shell Set or show the shell-specific Python version
install Install a Python version using python-build
uninstall Uninstall a specific Python version
update Update the cached version DB
rehash Rehash pyenv shims (run this after installing executables)
vname Show the current Python version
version Show the current Python version and its origin
version-name Show the current Python version
versions List all Python versions available to pyenv
exec Runs an executable by first preparing PATH so that the selected Python
which Display the full path to an executable
whence List all Python versions that contain the given executable
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv-win/pyenv-win#readme
C:\Users\name>pyenv commands
--version
commands
duplicate
exec
export
global
help
install
local
rehash
shell
shims
uninstall
update
version-name
version
versions
vname
whence
which
C:\Users\name>pyenv version
No global python version has been set yet. Please set the global version by typing:
pyenv global 3.7.2
C:\Users\user>pyenv local
no local version configured for this directory
C:\Users\user>pyenv global
no global version configured
C:\Users\user>pyenv local 3.9-64
pyenv specific python requisite didn't meet. Project is using different version of python.
Install python '3.9-64' by typing: 'pyenv install 3.9-64'
My Note: Version name from 'https://www.python.org/downloads/' is different to those provided by 'pyenv'. This version was already installed locally, but it is outside the control of this Python version manager, so it is not visible to the manager.
C:\Users\user>pyenv install 3.8.10-64
:: [Info] :: Mirror: https://www.python.org/ftp/python
pyenv-install: definition not found: local
My Note(s): This Python version is not part of the managed list although this version exists at 'https://www.python.org/downloads/'. So you must see the list provided by the manager. See all available versions with `pyenv install --list'.
C:\Users\user>pyenv install --list
Note: Review the list from this call and make your selection.
C:\Users\user>pyenv install 3.8.10
:: [Info] :: Mirror: https://www.python.org/ftp/python
:: [Downloading] :: 3.8.10 ...
:: [Downloading] :: From https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64-webinstall.exe
:: [Downloading] :: To C:\Users\user\.pyenv\pyenv-win\install_cache\python-3.8.10-amd64-webinstall.exe
:: [Installing] :: 3.8.10 ...
:: [Info] :: completed! 3.8.10
My Note(s): With this Python version manager, 'pyenv', following installation, it appears that one must designate the version as 'local' or 'global' after the installation which would follow the same paradigm as the Node.js Version Manager (NVM). Again, from what I can see, the Python version manager can only see what versions of Python the manager installs; and it can only uninstall a version it has installed with the Python version manager.
C:\Users\user>pyenv local 3.8.10
C:\Users\user>pyenv local
3.8.10
C:\Users\user>pyenv version
3.8.10 (set by C:\Users\user\.python-version)
C:\Users\user>pyenv versions
* 3.8.10 (set by C:\Users\user\.python-version)
C:\Users\user>pyenv vname
3.8.10
C:\Users\user>pyenv global
no global version configured
The following below is for working with packages.
See Also: https://www.freecodecamp.org/news/manage-multiple-python-versions-and-virtual-environments-venv-pyenv-pyvenv-a29fb00c296f/
From the above link, "When the environment is active, any packages can be installed to it via pip as normal. By default, the newly created environment will not include any packages already installed on the machine. As pip itself will not necessarily be installed on the machine. It is recommended to first upgrade pip to the latest version, using 'pip install --upgrade pip'." -- I performed the pip upgrade just before making these two calls to list the packages and their versions below.
c:\Users\user\AppData\Local\Programs\Python>pip list
Package Version
---------- -------
pip 22.1
setuptools 62.2.0
wheel 0.37.1
c:\Users\user\AppData\Local\Programs\Python>pip list --local
Package Version
---------- -------
pip 22.1
setuptools 62.2.0
wheel 0.37.1

Categories