python3.7(Ubuntu 16.04)的点子

时间:2019-02-04 00:42:15

标签: python python-3.x pip ubuntu-16.04

我无法为python 3.7安装pip。当我尝试在线搜索时,发现的一种解决方案是使用get-pip.py安装pip。但是,这对我来说是失败的:

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'

现在,要解决此问题,我发现应该安装libffi-dev软件包。但是,我验证了此软件包已在系统上安装。我不确定该如何解决。有人可以帮忙吗?

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.

更新: 我按照步骤从https://serverfault.com/questions/918335/best-way-to-run-python-3-7-on-ubuntu-16-04-which-comes-with-python-3-5安装Python 3.7。另外,当我检查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.

但是当我执行程序时,出现类似/usr/local/bin/python3.7: No module named pip的错误。

2 个答案:

答案 0 :(得分:4)

实际上,这要简单得多。 假设您的Linux基于Debian(例如,例如Ubuntu),则应根据需要为Python 3.x安装sudo apt install python3-pip或为Python 2.x安装sudo apt install python-pip的pip。

如果您的操作系统不是基于debian的,则只需更改使用中的软件包管理器(例如,使用yum或pacman而不是apt)。

Here,您还可以找到在Ubuntu 18.04上安装pip的指南。

希望这会有所帮助!

答案 1 :(得分:1)

我通过python3.7ppa)在Ubuntu 16.04中安装了sudo add-apt-repository ppa:deadsnakes/ppa(请参见detailed instructions ppa installation Python3.7

对我来说,尼克·特里西斯(Nick Tritsis)的答案无效。安装pip的唯一方法是直接下载文件get-pip.py并在python 3.7上运行(根据method in the official site

python3.7 get-pip.py

但是,像我一样,我收到了一条错误消息

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

一种不推荐的解决方案是使用sudo

sudo python3.7 get-pip.py

推荐的解决方案

推荐的解决方案是使用选项--user。 因此,我打开了文件get-pip.py,并更改了给出命令自变量的代码行:在此添加了自变量--user,使安装成为可能。

原始行:

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

修改行:

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

此修改后,python3.7 get-pip.py运行顺利。

已编辑:

@Matthew Strasiotto建议,也可以像这样在调用脚本时仅提供参数--user

  python3.7 get-pip.py --user

但是我还没有尝试过。