简体   繁体   English

python3.7 的 pip (Ubuntu 16.04)

[英]pip for python3.7 (Ubuntu 16.04)

I am not able to install pip for python 3.7.我无法为 python 3.7 安装 pip。 When I tried to search online, one solution I found was to install pip using get-pip.py.当我尝试在线搜索时,我发现的一种解决方案是使用 get-pip.py 安装 pip。 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.现在,为了解决这个问题,我发现应该安装libffi-dev包。 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 .更新:我按照步骤从https://serverfault.com/questions/918335/best-way-to-run-python-3-7-on-ubuntu-16-04-which-comes-with安装 Python 3.7 -python-3-5 Also, When I check for pip3.7 installation, I am getting the output as另外,当我检查 pip3.7 安装时,我得到的输出为

$ 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 .但是当我执行我的程序时,我收到一个错误,如/usr/local/bin/python3.7: No module named pip

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.假设您的 Linux 是基于 Debian 的(例如,Ubuntu),您应该根据需要使用sudo apt install python3-pip for Python 3.x sudo apt install python3-pip ,或者使用sudo apt install python-pip for Python 2.x sudo apt install python-pip

If your OS is not debian based, just change the package manager in use (for example use yum or pacman instead of apt).如果您的操作系统不是基于 debian 的,只需更改正在使用的包管理器(例如使用 yum 或 pacman 而不是 apt)。

Here , you can also find a guide for installing pip on Ubuntu 18.04. 在这里,您还可以找到在 Ubuntu 18.04 上安装 pip 的指南。

Hope this helps!希望这可以帮助!

I installed python3.7 in Ubuntu 16.04 via ppa ( sudo add-apt-repository ppa:deadsnakes/ppa ) (See detailed instructions ppa installation Python3.7 )我通过ppa ( sudo add-apt-repository ppa:deadsnakes/ppa ) 在 Ubuntu 16.04 中安装了python3.7 (请参阅ppa 安装 Python3.7 的详细说明

For me, Nick Tritsis answer did not work.对我来说,Nick Tritsis 的回答没有用。 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 )安装pip的唯一方法是直接下载文件get-pip.py并在python 3.7上运行(根据官网方法

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

sudo python3.7 get-pip.py

Recommended Solution推荐方案

One can just supply the argument --user when calling the script like so:可以在调用脚本时提供参数--user ,如下所示:

  python3.7 get-pip.py --user

credits to @Matthew Strasiotto, who suggested me this solution.感谢@Matthew Strasiotto,他向我推荐了这个解决方案。

Alternative Solution替代方案

This alternative solution is for fun;这种替代解决方案是为了好玩; it is more complicated than the recommended: We can add the option --user into the file.它比推荐的更复杂:我们可以将选项--user添加到文件中。

So we open the file get-pip.py and we change the code line where the command arguments are given: we added there the argument --user that makes installation possible.所以我们打开文件get-pip.py并更改给出命令参数的代码行:我们在那里添加了参数--user使安装成为可能。

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.修改后python3.7 get-pip.py运行流畅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM