10

I am not able to install pip for python 3.7. When I tried to search online, one solution I found was to install pip using get-pip.py. However, it's failing for me:

sudo python3.7 get-pip.py
Traceback (most recent call last):
  File "get-pip.py", line 21373, in <module>
    main()
  File "get-pip.py", line 197, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    import pip._internal
  File "/tmp/tmp3273u8va/pip.zip/pip/_internal/__init__.py", line 40, in <module>
  File "/tmp/tmp3273u8va/pip.zip/pip/_internal/cli/autocompletion.py", line 8, in <module>
  File "/tmp/tmp3273u8va/pip.zip/pip/_internal/cli/main_parser.py", line 12, in <module>
  File "/tmp/tmp3273u8va/pip.zip/pip/_internal/commands/__init__.py", line 6, in <module>
  File "/tmp/tmp3273u8va/pip.zip/pip/_internal/commands/completion.py", line 6, in <module>
  File "/tmp/tmp3273u8va/pip.zip/pip/_internal/cli/base_command.py", line 19, in <module>
  File "/tmp/tmp3273u8va/pip.zip/pip/_internal/download.py", line 37, in <module>
  File "/tmp/tmp3273u8va/pip.zip/pip/_internal/utils/glibc.py", line 3, in <module>
  File "/usr/local/lib/python3.7/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

Now, to resolve this, I found that libffi-dev package should be installed. However, I verified that this package is already installed on my system. I am not sure how should I resolve this. Can someone please help?

sudo apt-get install libffi-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libffi-dev is already the newest version (3.2.1-4).
0 upgraded, 0 newly installed, 0 to remove and 50 not upgraded.

Update: I followed the steps to install Python 3.7 from https://serverfault.com/questions/918335/best-way-to-run-python-3-7-on-ubuntu-16-04-which-comes-with-python-3-5. Also, When I check for pip3.7 installation, I am getting the output as

$ pip3.7 --version
pip 19.0.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
$ sudo apt install python3-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-pip is already the newest version (8.1.1-2ubuntu0.4).
0 upgraded, 0 newly installed, 0 to remove and 50 not upgraded.

But when I execute my program, I get an error like /usr/local/bin/python3.7: No module named pip.

Apoorv Gupta
  • 399
  • 1
  • 4
  • 16

2 Answers2

8

Actually it's a lot simpler. Assuming your Linux is Debian-based (for exaxample, Ubuntu), you should install pip with sudo apt install python3-pip for Python 3.x as you wish, or with sudo apt install python-pip for Python 2.x.

If your OS is not debian based, just change the package manager in use (for example use yum or pacman instead of apt).

Here, you can also find a guide for installing pip on Ubuntu 18.04.

Hope this helps!

Community
  • 1
  • 1
nic3ts
  • 347
  • 1
  • 2
  • 13
  • 1
    That's exactly what I tried. I have updated my question with more details. It looks like I have pip installed, but python3.7 isn't able to link to it. – Apoorv Gupta Feb 04 '19 at 00:56
  • Open a terminal & run `sudo apt install python3-pip`. Does it return `python-pip is already the newest version`? If not, that is your problem. The answer from the ServerFault community question you posted doesn't install python3--pip .. – nic3ts Feb 04 '19 at 01:00
  • 2
    Yes exactly, it returns ```python3-pip is already the newest version```. But my problem is that python3.7 is not able to recognize the pip and throws an error as stated in mine update. – Apoorv Gupta Feb 04 '19 at 01:02
  • 2
    Hmmm. Interesting. Let's try `sudo apt install --reinstall python3.7 python3-pip`. – nic3ts Feb 04 '19 at 01:09
  • 1
    I am sorry, it could be a silly question. When I am trying to reinstall python3.7, it says ``` E: Unable to locate package python3.7 E: Couldn't find any package by glob 'python3.7' E: Couldn't find any package by regex 'python3.7' ```. Do I need to update the repo first? – Apoorv Gupta Feb 04 '19 at 01:12
  • What OS are you currently using? – nic3ts Feb 04 '19 at 01:13
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/187826/discussion-between-nick-tritsis-and-apoorv-gupta). – nic3ts Feb 04 '19 at 01:18
  • 1
    So, Nick suggested reinstalling python3.7 from the package(serverfault link) I used. When I reinstalled it, it worked. – Apoorv Gupta Feb 04 '19 at 01:33
6

I installed python3.7 in Ubuntu 16.04 via ppa (sudo add-apt-repository ppa:deadsnakes/ppa) (See detailed instructions ppa installation Python3.7)

For me, Nick Tritsis answer did not work. The only way to install pip was directly downloading the file get-pip.py and running it on python 3.7 (according to the method in the official site)

python3.7 get-pip.py

However, as I did so I got an error message

ERROR: Could not install packages due to an 
EnvironmentError: [Errno 13] Permission denied:

One not recommended solution is to use sudo:

sudo python3.7 get-pip.py

Recommended Solution

One can just supply the argument --user when calling the script like so:

  python3.7 get-pip.py --user

credits to @Matthew Strasiotto, who suggested me this solution.

Alternative Solution

This alternative solution is for fun; it is more complicated than the recommended: We can add the option --user into the file.

So we open the file get-pip.pyand we change the code line where the command arguments are given: we added there the argument --user that makes installation possible.

Original line:

# Add our default arguments
 args = ["install", "--upgrade", "--force-reinstall"] + args

Modified line:

# Add our default arguments
args = ["install", "--user", "--upgrade", "--force-reinstall"] + args

After this modification python3.7 get-pip.py runs smooth.

loved.by.Jesus
  • 2,266
  • 28
  • 34
  • 1
    This should be accepted answer, thanks for posting! – Greg0ry Mar 20 '20 at 05:45
  • this did not work for me. I get this error (its the same error if I use without the --user parameter ): WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/pip/ ERROR: Could not find a version that satisfies the requirement pip (from versions: none) ERROR: No matching distribution found for pip – objectNotFound Jun 28 '20 at 20:32
  • Note: Iam on Ubuntu 16.04 behind a corporate proxy ... will greatly appreciate any help. Spent enormous amount of time already on what should be a trivial thing. But then this is the world of linux. Pain is the default setting – objectNotFound Jun 28 '20 at 20:41
  • @objectNotFound the error sounds heavy. If it is about the `connection`, it may have nothing to do with the `--user` folder, but rather with your internet (may be firewall?)—just pure guessing. I'll pray for you, it is the only thing I can do; please report any success. – loved.by.Jesus Jun 28 '20 at 21:26
  • connection is not the issue as apt pkg manager is able to download from internet. Anyone got around that issue using this method: https://askubuntu.com/a/880147/1100134 but now I have new problem ... cannot install pywinrm using the same method ( i.e downloading the tar file , extracting and running setup.py ) ... as I said Pain comes standard and compulsory in linux world. Quite possibly the worst OS platform out there. Anyways thanks for your help/prayers. – objectNotFound Jun 28 '20 at 21:56
  • the get-pip url is no longer maintained, you might try this url `https://bootstrap.pypa.io/get-pip.py` – xiaojueguan Jul 05 '20 at 03:40