简体   繁体   English

Linux终端使用Pip获取Python包报错

[英]Error When Using Pip To Get Python Packages On Linux Terminal

When I try to install a python package (cryptography in this case) in the Linux terminal, I get an error.当我尝试在 Linux 终端中安装 python package(在本例中为加密)时,出现错误。 I am using Python version 3.8.我正在使用 Python 3.8 版。 Here's the code:这是代码:
Input: python3.8 -m pip install cryptography or pip install cryptography输入: python3.8 -m pip install cryptographypip install cryptography

Output (anything after "Installing build dependencies... error" is in RED): Output(“正在安装构建依赖项...错误”之后的任何内容都是红色的):

Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting cryptography
  Using cached cryptography-36.0.1.tar.gz (572 kB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python3.8
/usr/local/lib/python3.8/site-packages/pip install --ignore-installed
--no-user --prefix /tmp/pip-build-env-j3i9og4s/overlay
--no-warn-script-location --no-binary :none: --only-binary :none: -i
https://pypi.org/simple --extra-index-url
https://www.piwheels.org/simple -- 'setuptools>=40.6.0' wheel
'cffi>=1.12; platform_python_implementation != '"'"'PyPy'"'"''
'setuptools-rust>=0.11.4'
       cwd: None
  Complete output (26 lines):
  Looking in indexes: https://pypi.org/simple,
https://www.piwheels.org/simple, https://www.piwheels.org/simple
  Collecting setuptools>=40.6.0
    Using cached setuptools-60.9.3-py3-none-any.whl (1.1 MB)
  Collecting wheel
    Using cached wheel-0.37.1-py2.py3-none-any.whl (35 kB)
  Collecting cffi>=1.12
    Using cached cffi-1.15.0.tar.gz (484 kB)
      ERROR: Command errored out with exit status 1:
       command: /usr/local/bin/python3.8 -c 'import sys, setuptools,
tokenize; sys.argv[0] =
'"'"'/tmp/pip-install-9sokml3p/cffi/setup.py'"'"';
__file__='"'"'/tmp/pip-install-9sokml3p/cffi/setup.py'"'"';f=getattr(tokenize,
'"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"',
'"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))'
egg_info --egg-base /tmp/pip-pip-egg-info-5ylb3zxi
           cwd: /tmp/pip-install-9sokml3p/cffi/
      Complete output (11 lines):
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py",
line 19, in <module>
          from setuptools.dist import Distribution
        File "/usr/local/lib/python3.8/site-packages/setuptools/dist.py",
line 34, in <module>
          from setuptools import windows_support
        File "/usr/local/lib/python3.8/site-packages/setuptools/windows_support.py",
line 2, in <module>
          import ctypes
        File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
          from _ctypes import Union, Structure, Array
      ModuleNotFoundError: No module named '_ctypes'
      ----------------------------------------
  ERROR: Command errored out with exit status 1: python setup.py
egg_info Check the logs for full command output.
  WARNING: You are using pip version 20.1.1; however, version 22.0.3
is available.
  You should consider upgrading via the '/usr/local/bin/python3.8 -m
pip install --upgrade pip' command.
  ----------------------------------------
ERROR: Command errored out with exit status 1:
/usr/local/bin/python3.8 /usr/local/lib/python3.8/site-packages/pip
install --ignore-installed --no-user --prefix
/tmp/pip-build-env-j3i9og4s/overlay --no-warn-script-location
--no-binary :none: --only-binary :none: -i https://pypi.org/simple
--extra-index-url https://www.piwheels.org/simple --
'setuptools>=40.6.0' wheel 'cffi>=1.12; platform_python_implementation
!= '"'"'PyPy'"'"'' 'setuptools-rust>=0.11.4' Check the logs for full
command output.

I don't really understand what this means, and I'd like some assistance installing a package and trying to fix this error.我真的不明白这是什么意思,我需要一些帮助来安装 package 并尝试修复此错误。 Thanks!谢谢! -Shane -Shane

EDIT: I found near the beginning the text 'Command errored out with exit status 1' EDIT: I have installed libffi-dev.编辑:我在开头找到文本“命令错误,退出状态为 1” 编辑:我已经安装了 libffi-dev。

Solved by upgrading pip to pip3 using sudo apt-get -y install python3-pip .通过使用sudo apt-get -y install python3-pip将 pip 升级到 pip3 解决。

Looks like you may need to install libffi-dev .看起来您可能需要安装libffi-dev I'm not sure your distro, but it'll be there.我不确定你的发行版,但它会在那里。 Distro is raspbian.发行版是树莓派。

Install with:安装:

apt-get install libffi-dev

There are other questions that looks similar since they have the _ctypes issue, but I won't mark this as a duplicate since your question is exactly the same.还有其他看起来相似的问题,因为它们有_ctypes问题,但我不会将其标记为重复,因为您的问题完全相同。 I think the underlying root cause is probably the same.我认为根本原因可能是相同的。 See here and here .请参阅此处此处

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

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