我在Ubuntu 18.04.1上并行安装了Python 2和3:
#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运行为Python2编写的脚本(并且使用调用pycrypto的simple-crypt),但我无法在python3 (pip3)下安装simple-crypt,因为pycrypto安装失败,即使它们都安装在Python2下。
我在安装过程中看到以下错误:
#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('"'"'rn'"'"', '"'"'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('"'"'rn'"'"', '"'"'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('"'"'rn'"'"', '"'"'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.
#
我想可能是这样的:
src/MD2.c:31:10: fatal error: Python.h: No such file or directory
我的问题是:
- 我可以从本地下载包并安装吗?
- 我可以从现有的Python2安装安装到Python3吗?
- 我可以告诉Python3如何"使用"当前安装在Python2下的软件包吗?
任何想法/建议吗?
这只是问题1的部分答案:
- 我可以下载软件包并从本地tar安装吗?
Install Python Module manual:
# 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
如果一切顺利,新模块现在应该出现在已安装/可用模块列表中。
尝试pip install pipwin,然后pipwin安装pycrypto,但如果这不起作用,这意味着你可能不得不将python版本降级到3.3,因为不支持1.5.2。这是因为pycrypto是在2013年发布的,当时python 3.8还没有发布,所以没有支持。