English
Install Python packages
It's possible to install Python packages without internet by downloading the source code of a package compressed in tar.gz, copying it to the machine via scp/other methods, and running (having previously loaded a Python module):
$> tar xzf {package}.tar.gz
$> cd {package}
$> python setup.py install / pip install . (both methods usually work)
Requirements to install packages
Requirements to install packages networked (must have Internet access)
Connect to a login4 of MareNostrum5:
mylaptop$> ssh {username}@glogin4.bsc.es
mylaptop$> ssh {username}@alogin4.bsc.esIMPORTANTThe MareNostrum5 login4 are restricted to BSC staff and are only accessible from the BSC internal network or the Virtual Private Network (VPN).
Check the Internet connectivity from glogin4/alogin4, for example:
$> wget --tries=3 --timeout=5 -q --spider google.com && echo "Networked" || echo "Non-networked"
Networked
Check the Python interpreter
Load Python in the session, for example:
$> module purge && module load oneapi hdf5 python
Ensure you can run Python from the command line:
$> which python
/apps/GPP/PYTHON/3.12.1/INTEL/bin/python
$> python --version
Python 3.12.1
Check the 'pip' package manager
pip is the recommended package installer, allowing packages installation from PyPI (Python Package Index), local projects, or directly from distribution files. It also supports version control.
"python3 -m pip" executes pip using the Python interpreter you specified as python3.
Ensure you can run pip from the command line:
$> python -m pip --version
pip 24.0 from /apps/GPP/PYTHON/3.12.1/INTEL/lib/python3.12/site-packages/pip (python 3.12)
Install and manage packages
Install packages
Install a package from PyPI:
$> python -m pip install SomePackage # Latest version
$> python -m pip install "SomePackage==1.0.4" # Specific version
$> python -m pip install "SomePackage>=1.0.4" # Minimum versionInstall a package locally (from PyPI):
$> python3 -m pip install --user SomePackage # At the user default location
Or:
$> export PYTHONUSERBASE=/path/to/my/python/local/project
$> python3 -m pip install --user SomePackageInstall a list of packages specified in a requirements file:
$> python3 -m pip install -r requirements.txt
Maybe you want to do something like this:
SomePythonEnv$> python3 -m pip freeze > requirements.txt
MyPythonEnv$> python3 -m pip install -r requirements.txt
Install packages from a source file:
$> python3 -m pip install SomePackage-1.0.4.tar.gz
Update packages
Upgrade an already installed package to the latest from PyPI:
$> python3 -m pip install --upgrade SomePackage
# Dependencies are upgraded only when they don't meet
# the requirements of the upgraded packagesOr:
$> python3 -m pip install SomePackage --upgrade --upgrade-strategy eager
# Dependencies are upgraded regardless of whether the currently
# the currently installed version meets the requirements
# of the upgraded package
Uninstall packages
Uninstall a package:
$> python3 -m pip uninstall SomePackage
$> python3 -m pip uninstall SomePackage --yes # Don't ask for confirmation, also '-y'Uninstall a list of packages from a requirements file:
$> python3 -m pip uninstall -r requirements.txt [--yes, -y]
Verification of installed packages
Show the list of existing packages:
$> python3 -m pip list # Packages that are globally installed
$> python3 -m pip list --user # Packages that are locally installedOr:
$> python3 -m pip freeze
$> python3 -m pip freeze --userIt can also be helpful:
$> python3 -m pip list [--user] | grep -i SomePackage
$> python3 -m pip freeze [--user] | grep -i SomePackage
Show the list of outdated packages (and show the latest version available):
$> python3 -m pip list --outdated
Show location of existing packages:
$> python3 -m site # Globally installed packages
$> python3 -m site --user-site # Locally installed packagesShow details of a specific package:
$> python3 -m pip show SomePackage
Verify that installed packages have compatible dependencies:
$> python3 -m pip check
No broken requirements found. # The desirable