-5

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.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • Here's the [error codes manual](https://www.daemon-systems.org/man/errno.2.html). If you scroll down, ERRNO (error number) 2 is simply the number for a missing file or directory. – rassar Aug 24 '23 at 20:11
  • 1
    Did you actually download `get-pip.py`? That command only works if you have a copy of that file in your current working directory; clearly you don't. – ShadowRanger Aug 24 '23 at 20:12
  • `sudo apt install python3-pip` probably works; and is probably the better solution, since that matches a system-installed Python with a system-installed Pip. – 9769953 Aug 24 '23 at 20:18
  • Beside the point, but that alias doesn't affect the command name `python3`, it's for the command name `python`. – wjandrea Aug 24 '23 at 20:26
  • 1
    Can you please clarify what you are asking? The message you have provided already says what errno 2 means: "No such file or directory", in your case specifically when trying to open get-pip.py (i.e. Python can’t open the file because there is no such file). – MisterMiyagi Aug 24 '23 at 20:33
  • 1
    Cross-posted: https://askubuntu.com/q/1483534/158442 https://unix.stackexchange.com/q/754865/70524 – muru Aug 25 '23 at 01:04

2 Answers2

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'
wjandrea
  • 28,235
  • 9
  • 60
  • 81
1

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.

tdelaney
  • 73,364
  • 6
  • 83
  • 116