1

My Ubuntu 21.04 came with preinstalled with python 3.

I installed python 2.7 in parallel since all my programs are in python 2.7.

In my modules, import dateutil is used.

Since the system default is python 3, how do I install python-dateutil in python 2.7?

Thanks.

Vineet
  • 624
  • 1
  • 11
  • 26
  • @aaossa I tried it. Result is --- vin@vinLap:~$ python2.7 -m pip install dateutil /usr/bin/python2.7: No module named pip – Vineet Mar 03 '22 at 15:14
  • @aaossa --- :~$ sudo apt-get install python-pip it results in error -- Package python-pip is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: python3-pip E: Package 'python-pip' has no installation candidate – Vineet Mar 03 '22 at 15:25
  • Looks like pip has dropped support for python 2.7 – Vineet Mar 03 '22 at 15:31
  • 1
    for pip, solution of @betontalpfa worked https://stackoverflow.com/questions/65558034/cant-install-pip-anymore-with-python-2-7 – Vineet Mar 03 '22 at 15:55
  • @aaossa $ python2.7 -m pip install dateutil Collecting dateutil Could not find a version that satisfies the requirement dateutil (from versions: ) No matching distribution found for dateutil You are using pip version 9.0.0, however version 22.0.3 is available. You should consider upgrading via the 'pip install --upgrade pip' command. – Vineet Mar 03 '22 at 15:57
  • @aaossa yes I tried it. But it is not there. ```>>> import dateutil Traceback (most recent call last): File "", line 1, in ImportError: No module named dateutil ``` – Vineet Mar 03 '22 at 16:04
  • @aaossa ```$ python2.7 Python 2.7.18 (default, Mar 9 2021, 11:09:26) [GCC 10.2.1 20210306] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import dateutil Traceback (most recent call last): File "", line 1, in ImportError: No module named dateutil``` – Vineet Mar 03 '22 at 16:11
  • 1
    Try `python2.7 -m pip install python-dateutil` – aaossa Mar 03 '22 at 16:13
  • @aaossa exception encountered ... ```You are using pip version 9.0.0, however version 22.0.3 is available. You should consider upgrading via the 'pip install --upgrade pip' command. ``` – Vineet Mar 03 '22 at 16:15
  • That's a waning, not an error. Did it show any additional output? – aaossa Mar 03 '22 at 16:16
  • 1
    @aaossa ```sudo``` was missing. Now it is installed. Thank you very much. You may add it as an answer. I will tag it as accepted. Thanks again. – Vineet Mar 03 '22 at 16:18

1 Answers1

2

FTR, these steps were necessary:

  1. Install pip in Python 2.7. This answer in another SO question worked for OP.

  2. Install dateutil using the corresponding pip version:

    sudo python2.7 -m pip install python-dateutil
    
Brian Burns
  • 20,575
  • 8
  • 83
  • 77
aaossa
  • 3,763
  • 2
  • 21
  • 34