skip to Main Content

I am setting up pip using the official documentation on an Ubuntu 22.04 LTS system, and when I execute the python get-pip.py command, I get an error message stating:

python3: can't open file '/home/usr/get-pip.py': [Errno 2] No such file or directory

I thought it was an error on my part because python commands don’t work in Linux distros and I aliased the python3 command:

alias python='python3'

The problem persisted. A quick Google Search led me to this solution and my error was solved.

Afterwards, I did some digging on what [Errno 2] is but all of the material I encountered was hyperfocused on solving this error and not what causes it.

2

Answers


  1. It’s not pip-specific. It’s documented in errno, specifically:

    errno.ENOENT

    No such file or directory. This error is mapped to the exception FileNotFoundError.

    If you didn’t know to look for "No such file or directory", you could use os.strerror() or errno.errorcode:

    >>> import os
    >>> os.strerror(2)
    'No such file or directory'
    >>> 
    >>> import errno
    >>> errno.errorcode[2]
    'ENOENT'
    
    Login or Signup to reply.
  2. The standard linux error codes can be found by running man 3 errno or referencing errno(3) — Linux manual page.

       ENOENT          No such file or directory (POSIX.1-2001).
    
                       Typically, this error results when a specified pathname does not exist, or one  of
                       the components in the directory prefix of a pathname does not exist, or the speci‐
                       fied pathname is a dangling symbolic link.
    

    It means what it says: the file doesn’t exist.

    Python commands do work on linux and there was no need to alias python here. You ran python get-pip.py and python told you that it couldn’t find get-pip.py. You ran from the current working directory /home/usr/ but python tried to be friendly and show the absolute path of the non-existent file.

    The instructions told you to download get-pip.py, change to the download directory and then run the command. You must have missed one of those steps.

    The solution that worked for you downloaded get-pip.py into the current working directory and executed it. That’s why it worked. It may not have been so wise to sudo first as you risk overwriting your platform-installed python as opposed to installing a local python.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search