pip for python3.7 (Ubuntu 16.04)

醉酒当歌 提交于 2021-01-21 04:25:07

问题


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.


回答1:


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!




回答2:


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.



来源:https://stackoverflow.com/questions/54509031/pip-for-python3-7-ubuntu-16-04

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!