Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip for python3.7 (Ubuntu 16.04)

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.

like image 369
Apoorv Gupta Avatar asked Feb 04 '19 00:02

Apoorv Gupta


People also ask

Can I use pip install in Ubuntu?

Pip is a helpful command line package manager and installer for Ubuntu. Using various commands, pip allows you to manage Python software packages from the Ubuntu terminal. In this tutorial, you have learned how to install pip on Ubuntu machines running both Python 2 and Python 3.

Is pip compatible with python3?

The Python 3 installer gives you the option to install pip when installing Python on your system. In fact, the option to install pip with Python is checked by default, so pip should be ready for you to use after installing Python.


2 Answers

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!

like image 97
nic3ts Avatar answered Oct 01 '22 02:10

nic3ts


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.

like image 43
loved.by.Jesus Avatar answered Oct 01 '22 02:10

loved.by.Jesus