简体   繁体   English

安装Python加密错误

[英]Installing Python Cryptography error

When running the pip install cryptography I get the following result 运行pip install cryptography我得到以下结果

pip install cryptography
Downloading/unpacking cryptography
Running setup.py egg_info for package cryptography
Traceback (most recent call last):
  File "<string>", line 16, in <module>
  File "/tmp/pip-build-root/cryptography/setup.py", line 174, in <module>
    "test": PyTest,
  File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command
    cmd_obj.run()
  File "<string>", line 14, in replacement_run
  File "/usr/lib/python2.6/site-packages/setuptools/command/egg_info.py", line 254, in find_sources
    mm.run()
  File "/usr/lib/python2.6/site-packages/setuptools/command/egg_info.py", line 308, in run
    self.add_defaults()
  File "/usr/lib/python2.6/site-packages/setuptools/command/egg_info.py", line 332, in add_defaults
    sdist.add_defaults(self)
  File "/usr/lib/python2.6/site-packages/setuptools/command/sdist.py", line 187, in add_defaults
    build_py = self.get_finalized_command('build_py')
  File "/usr/lib64/python2.6/distutils/cmd.py", line 319, in get_finalized_command
    cmd_obj.ensure_finalized()
  File "/usr/lib64/python2.6/distutils/cmd.py", line 117, in ensure_finalized
    self.finalize_options()
  File "/usr/lib/python2.6/site-packages/setuptools/command/build_py.py", line 61, in finalize_options
    _build_py.finalize_options(self)
  File "/usr/lib64/python2.6/distutils/command/build_py.py", line 50, in finalize_options
    ('force', 'force'))
  File "/usr/lib64/python2.6/distutils/cmd.py", line 305, in set_undefined_options
    src_cmd_obj.ensure_finalized()
  File "/usr/lib64/python2.6/distutils/cmd.py", line 117, in ensure_finalized
    self.finalize_options()
  File "/tmp/pip-build-root/cryptography/setup.py", line 88, in finalize_options
    self.distribution.ext_modules = get_ext_modules()
  File "/tmp/pip-build-root/cryptography/setup.py", line 65, in get_ext_modules
    from cryptography.hazmat.primitives import constant_time, padding
  File "cryptography/hazmat/primitives/constant_time.py", line 49, in <module>
    _ffi = cffi.FFI()
  File "/tmp/pip-build-root/cryptography/cffi-0.8.6-py2.6-linux-x86_64.egg/cffi/api.py", line 56, in __init__
    import _cffi_backend as backend
ImportError: /tmp/pip-build-root/cryptography/cffi-0.8.6-py2.6-linux-x86_64.egg/_cffi_backend.so: failed to map segment from shared object: Operation not permitted
Complete output from command python setup.py egg_info:
running egg_info

writing requirements to pip-egg-info/cryptography.egg-info/requires.txt

writing pip-egg-info/cryptography.egg-info/PKG-INFO

writing top-level names to pip-egg-info/cryptography.egg-info/top_level.txt

writing dependency_links to pip-egg-info/cryptography.egg-info/dependency_links.txt

warning: manifest_maker: standard file '-c' not found

Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/tmp/pip-build-root/cryptography/setup.py", line 174, in <module>

    "test": PyTest,

  File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup

    dist.run_commands()

  File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands

    self.run_command(cmd)

  File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command

    cmd_obj.run()

  File "<string>", line 14, in replacement_run

  File "/usr/lib/python2.6/site-packages/setuptools/command/egg_info.py", line 254, in find_sources

    mm.run()

  File "/usr/lib/python2.6/site-packages/setuptools/command/egg_info.py", line 308, in run

    self.add_defaults()

  File "/usr/lib/python2.6/site-packages/setuptools/command/egg_info.py", line 332, in add_defaults

    sdist.add_defaults(self)

  File "/usr/lib/python2.6/site-packages/setuptools/command/sdist.py", line 187, in add_defaults

    build_py = self.get_finalized_command('build_py')

  File "/usr/lib64/python2.6/distutils/cmd.py", line 319, in get_finalized_command

    cmd_obj.ensure_finalized()

  File "/usr/lib64/python2.6/distutils/cmd.py", line 117, in ensure_finalized

    self.finalize_options()

  File "/usr/lib/python2.6/site-packages/setuptools/command/build_py.py", line 61, in finalize_options

    _build_py.finalize_options(self)

  File "/usr/lib64/python2.6/distutils/command/build_py.py", line 50, in finalize_options

    ('force', 'force'))

  File "/usr/lib64/python2.6/distutils/cmd.py", line 305, in set_undefined_options

    src_cmd_obj.ensure_finalized()

  File "/usr/lib64/python2.6/distutils/cmd.py", line 117, in ensure_finalized

    self.finalize_options()

  File "/tmp/pip-build-root/cryptography/setup.py", line 88, in finalize_options

    self.distribution.ext_modules = get_ext_modules()

  File "/tmp/pip-build-root/cryptography/setup.py", line 65, in get_ext_modules

    from cryptography.hazmat.primitives import constant_time, padding

  File "cryptography/hazmat/primitives/constant_time.py", line 49, in <module>

     _ffi = cffi.FFI()

  File "/tmp/pip-build-root/cryptography/cffi-0.8.6-py2.6-linux-x86_64.egg/cffi/api.py", line 56, in  __init__

    import _cffi_backend as backend

ImportError: /tmp/pip-build-root/cryptography/cffi-0.8.6-py2.6-linux-x86_64.egg/_cffi_backend.so: failed to map segment from shared object: Operation not permitted

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-root/cryptography
Storing complete log in /root/.pip/pip.log

I'm guessing theirs something wrong with some dependencies I'm missing? 我猜他们错过了一些我错过的依赖项?

When I run the sudo yum install gcc libffi-devel python-devel openssl-devel to install the dependencies that are required, I get the following result 当我运行sudo yum install gcc libffi-devel python-devel openssl-devel来安装所需的依赖项时,我得到以下结果

sudo yum install gcc libffi-devel python-devel openssl-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.econdc.com
 * epel: mirrors.coreix.net
 * extras: centos.hyve.com
 * updates: mirror.sov.uk.goscomb.net
Setting up Install Process
Package gcc-4.4.7-4.el6.x86_64 already installed and latest version
Package libffi-devel-3.0.5-3.2.el6.x86_64 already installed and latest version
Package python-devel-2.6.6-52.el6.x86_64 already installed and latest version
Package openssl-devel-1.0.1e-16.el6_5.15.x86_64 already installed and latest version
Nothing to do

Does anyone have any suggestions as to what I'm missing? 有没有人对我缺少的东西有任何建议?

Chroot and remounting /tmp are unnecessary because you are using pip which provides this option ( pip help install ): chroot环境和重新安装/tmp是不必要的,因为你正在使用pip提供该选项( pip help install ):

-b, --build <dir>    Directory to unpack packages into and build in.

Simply set that to a directory that does NOT have noexec . 只需将其设置为不具有noexec的目录即可。

I was having the same issue and it happens that the server had /tmp mounted with noexec. 我遇到了同样的问题,而且服务器的/ tmp安装了noexec。 This was causing all sorts of problems. 这导致了各种各样的问题。 A way to solve it is to create a "chroot" environment that contains a "/tmp" directory that allows for file execution: 解决它的一种方法是创建一个“chroot”环境,其中包含允许文件执行的“/ tmp”目录:

Follow this article for instructions of how to circumvent this. 请按照本文的说明来了解如何避免这种情况。

  1. Create a "chroot" environment that contains a "/tmp" directory that allows for file execution: 创建一个“chroot”环境,其中包含允许文件执行的“/ tmp”目录:

    mkdir -p /root/chroot /root/tmp mkdir -p / root / chroot / root / tmp
    mount --bind / /root/chroot mount --bind // root / chroot
    mount --bind /root/tmp /root/chroot/tmp mount --bind / root / tmp / root / chroot / tmp
    chroot /root/chroot chroot / root / chroot

  2. "chroot" into the environment you created: “chroot”进入你创造的环境:

    chroot /root/chroot chroot / root / chroot

  3. At this point, you are in the "chroot" environment and can run any commands you need to. 此时,您处于“chroot”环境中,可以运行您需要的任何命令。

    Run the instalation 运行安装

  4. When you are done, type the following commands: 完成后,键入以下命令:

    exit 出口

    umount -l /root/chroot umount -l / root / chroot

在某些系统上,这应该工作:

TMPDIR=~/tmp pip install cryptography

Also you could mount that volume without noexec flag, by removing it from /etc/fstab or executing mount -o remount exec /tmp 你也可以在没有noexec标志的情况下安装该卷,方法是从/ etc / fstab中删除它或执行mount -o remount exec /tmp

fstab solution is less safer, it can be considered a security breach, since anyone could put script on /tmp and execute them. fstab解决方案不那么安全,它可以被认为是安全漏洞,因为任何人都可以将脚本放在/ tmp上并执行它们。

More info here . 更多信息在这里

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

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