首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法在python3下安装pycrypto (使用pip3),但它是在python[2]下并行安装的

无法在python3下安装pycrypto (使用pip3),但它是在python[2]下并行安装的
EN

Stack Overflow用户
提问于 2021-03-07 08:06:33
回答 2查看 1.1K关注 0票数 0

我在Ubuntu18.04.1上并行安装了Python 2和3:

代码语言:javascript
运行
复制
#uname -a
Linux mysvr-1 5.4.0-65-generic #73~18.04.1-Ubuntu SMP Tue Jan 19 09:02:24 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

#python --version
Python 2.7.17

#python3 --version 
Python 3.8.8

我正在尝试使用python3运行一个为python3编写的脚本(它使用了调用pycrypto的simple-crypt ),但是我不能在python3 (pip3)下安装simple-crypt,因为pycrypto安装失败,即使它们都安装在python2下很好。

在安装过程中,我看到以下错误:

代码语言:javascript
运行
复制
#python3 -m pip install simple-crypt
Collecting simple-crypt
  Using cached simple-crypt-4.1.7.tar.gz (10 kB)
Collecting pycrypto
  Using cached pycrypto-2.6.1.tar.gz (446 kB)
Building wheels for collected packages: simple-crypt, pycrypto
  Building wheel for simple-crypt (setup.py) ... done
  Created wheel for simple-crypt: filename=simple_crypt-4.1.7-py3-none-any.whl size=8933 sha256=35465628dbc2d4671aef879ccd6d24d09e01ca11afa173fd8d62c5cbcfb8e05b
  Stored in directory: /root/.cache/pip/wheels/7f/0b/04/30775cf18395f400fba1112955512e434a896bc5f0592eaf82
  Building wheel for pycrypto (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-wo7npi4x/pycrypto_1a5c9f1c1c3446a6a44b1061e80eedc8/setup.py'"'"'; __file__='"'"'/tmp/pip-install-wo7npi4x/pycrypto_1a5c9f1c1c3446a6a44b1061e80eedc8/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-31add99g
       cwd: /tmp/pip-install-wo7npi4x/pycrypto_1a5c9f1c1c3446a6a44b1061e80eedc8/
  Complete output (215 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.8
  creating build/lib.linux-x86_64-3.8/Crypto
  copying lib/Crypto/pct_warnings.py -> build/lib.linux-x86_64-3.8/Crypto
  ...
  <...many other lines of copying and creating...>
  ...
  Skipping optional fixer: buffer
  Skipping optional fixer: idioms
  Skipping optional fixer: set_literal
  Skipping optional fixer: ws_comma
  running build_ext
  running build_configure
  checking for gcc... gcc
  checking whether the C compiler works... yes
  ...
  <...many other successful checks...>
  ...
  checking for memset... yes
  configure: creating ./config.status
  config.status: creating src/config.h
  warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
  building 'Crypto.Hash._MD2' extension
  creating build/temp.linux-x86_64-3.8
  creating build/temp.linux-x86_64-3.8/src
  x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -fwrapv -Wall -fstack-protector-strong -Wformat -Werror=format-security -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python3.8 -c src/MD2.c -o build/temp.linux-x86_64-3.8/src/MD2.o
  src/MD2.c:31:10: fatal error: Python.h: No such file or directory
   #include "Python.h"
            ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pycrypto
  Running setup.py clean for pycrypto
Successfully built simple-crypt
Failed to build pycrypto
Installing collected packages: pycrypto, simple-crypt
    Running setup.py install for pycrypto ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-wo7npi4x/pycrypto_1a5c9f1c1c3446a6a44b1061e80eedc8/setup.py'"'"'; __file__='"'"'/tmp/pip-install-wo7npi4x/pycrypto_1a5c9f1c1c3446a6a44b1061e80eedc8/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-zy55j0yw/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/pycrypto
         cwd: /tmp/pip-install-wo7npi4x/pycrypto_1a5c9f1c1c3446a6a44b1061e80eedc8/
    Complete output (160 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.8
    ...
    <...many other lines of copying and creating...>
    ...
    Skipping optional fixer: buffer
    Skipping optional fixer: idioms
    Skipping optional fixer: set_literal
    Skipping optional fixer: ws_comma
    running build_ext
    running build_configure
    warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
    building 'Crypto.Hash._MD2' extension
    creating build/temp.linux-x86_64-3.8
    creating build/temp.linux-x86_64-3.8/src
    x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -fwrapv -Wall -fstack-protector-strong -Wformat -Werror=format-security -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python3.8 -c src/MD2.c -o build/temp.linux-x86_64-3.8/src/MD2.o
    src/MD2.c:31:10: fatal error: Python.h: No such file or directory
     #include "Python.h"
              ^~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-wo7npi4x/pycrypto_1a5c9f1c1c3446a6a44b1061e80eedc8/setup.py'"'"'; __file__='"'"'/tmp/pip-install-wo7npi4x/pycrypto_1a5c9f1c1c3446a6a44b1061e80eedc8/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-zy55j0yw/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/pycrypto Check the logs for full command output.

#

我想可能是这样的:

代码语言:javascript
运行
复制
src/MD2.c:31:10: fatal error: Python.h: No such file or directory

我有以下问题:

  1. 我可以下载这个包并从本地tar安装吗?
    1. 我可以从现有的Python2 Python2安装到Python3,告诉Python3如何‘使用’当前安装在Python2?

    下的软件包(并由Python2)使用。

有什么想法/建议吗?

EN

回答 2

Stack Overflow用户

发布于 2021-03-23 05:59:36

这只是对上文问题1的部分答复:

  1. 我可以下载这个包并从本地tar安装吗?

手动安装Python模块:

代码语言:javascript
运行
复制
# Verify the module is not already installed
python3 -m pip list
# As above - Python 2.x
python -m pip list

# Download the module
curl <MODULE_DOWNLOAD_URL> -o <MODULE_FILE_NAME>

# Make sure setuptools are up to date - Python 3.x
python3 -m pip install --upgrade setuptools
# As above - Python 2.x
python -m pip install --upgrade setuptools

# Extract the downloaded gzipped tar file if necessary
tar -xvf <MODULE_FILE_NAME>
# cd into the extracted module folder if created
cd <MODULE_FOLDER>

# Run the included setup.py script to install the module
python3 setup.py install
# Same for Python 2.x
python setup.py install

# Verify the module was successfully installed
python3 -m pip list
# As above - Python 2.x
python -m pip list

如果一切顺利,新模块现在应该出现在已安装/可用模块列表中。

票数 1
EN

Stack Overflow用户

发布于 2021-03-07 08:56:09

尝试pip安装pipwin,然后pipwin安装pycrypto,但是如果这不起作用,这意味着您可能不得不将您的python版本降到3.3,1.5.2不支持since.this,这是因为pycrypto是在2013年推出的,当时python3.8还没有发布,所以没有支持。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66514399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档