I am trying to use the pqcrypto library but can not resolve the issue:
Import "pqcrypto" could not be resolved Pylance (reportMissingImports)
I am using python 3.10.6 on a ubuntu 22.4 virtual machine (virtual box). Pip version 23.0.1.
Initially I could not pip install this library and constantly failed to build wheel during install.
× Building wheel for pqcrypto (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [49 lines of output]
A setup.py file already exists. Using it.
Traceback (most recent call last):
File "/tmp/pip-install-8f35n23e/pqcrypto_15372684f61345f19dab295f64d05a2a/setup.py", line 31, in <module>
setup(**setup_kwargs)
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.10/distutils/core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 459, in __init__
_Distribution.__init__(
File "/usr/lib/python3.10/distutils/dist.py", line 292, in __init__
self.finalize_options()
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 837, in finalize_options
ep(self)
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 858, in _finalize_setup_keywords
ep.load()(self, ep.name, value)
File "/tmp/pip-build-env-ifogc2y8/overlay/local/lib/python3.10/dist-packages/cffi/setuptools_ext.py", line 219, in cffi_modules
add_cffi_module(dist, cffi_module)
File "/tmp/pip-build-env-ifogc2y8/overlay/local/lib/python3.10/dist-packages/cffi/setuptools_ext.py", line 49, in add_cffi_module
execfile(build_file_name, mod_vars)
File "/tmp/pip-build-env-ifogc2y8/overlay/local/lib/python3.10/dist-packages/cffi/setuptools_ext.py", line 25, in execfile
exec(code, glob, glob)
File "compile.py", line 80, in <module>
algorithm_ffi = create_algorithm_ffi(algorithm, **kwargs)
File "compile.py", line 60, in create_algorithm_ffi
ffi = FFI()
File "/tmp/pip-build-env-ifogc2y8/overlay/local/lib/python3.10/dist-packages/cffi/api.py", line 54, in __init__
raise Exception("Version mismatch: this is the 'cffi' package version %s, located in %r. When we import the top-level '_cffi_backend' extension module, we get version %s, located in %r. The two versions should be equal; check your installation." % (
Exception: Version mismatch: this is the 'cffi' package version 1.15.1, located in '/tmp/pip-build-env-ifogc2y8/overlay/local/lib/python3.10/dist-packages/cffi/api.py'. When we import the top-level '_cffi_backend' extension module, we get version 1.15.0, located in '/usr/lib/python3/dist-packages/_cffi_backend.cpython-310-x86_64-linux-gnu.so'. The two versions should be equal; check your installation.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 261, in build_wheel
return _build_backend().build_wheel(wheel_directory, config_settings,
File "/tmp/pip-build-env-ifogc2y8/overlay/local/lib/python3.10/dist-packages/poetry/core/masonry/api.py", line 56, in build_wheel
return WheelBuilder.make_in(
File "/tmp/pip-build-env-ifogc2y8/overlay/local/lib/python3.10/dist-packages/poetry/core/masonry/builders/wheel.py", line 85, in make_in
wb.build(target_dir=directory)
File "/tmp/pip-build-env-ifogc2y8/overlay/local/lib/python3.10/dist-packages/poetry/core/masonry/builders/wheel.py", line 118, in build
self._build(zip_file)
File "/tmp/pip-build-env-ifogc2y8/overlay/local/lib/python3.10/dist-packages/poetry/core/masonry/builders/wheel.py", line 179, in _build
self._run_build_command(setup)
File "/tmp/pip-build-env-ifogc2y8/overlay/local/lib/python3.10/dist-packages/poetry/core/masonry/builders/wheel.py", line 217, in _run_build_command
subprocess.check_call(
File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python3', '/tmp/pip-install-8f35n23e/pqcrypto_15372684f61345f19dab295f64d05a2a/setup.py', 'build', '-b', '/tmp/pip-install-8f35n23e/pqcrypto_15372684f61345f19dab295f64d05a2a/build']' returned non-zero exit status 1.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pqcrypto
Failed to build pqcrypto
ERROR: Could not build wheels for pqcrypto, which is required to install pyproject.toml-based projects
To remedy this I downloaded the tar itself and installed with this command:
sudo python setup.py install
It seems to have installed but not satisfied the error. Subsequent pip install commands produce this:
$ pip install pqcrypto
Requirement already satisfied: pqcrypto in /home/mack/Desktop/RSAvsCK/venv/lib/python3.10/site-packages/pqcrypto-0.1.3-py3.10-linux-x86_64.egg (0.1.3)
Requirement already satisfied: cffi<2.0.0,>=1.14.2 in ./.eggs/cffi-1.15.1-py3.10-linux-x86_64.egg (from pqcrypto) (1.15.1)
Requirement already satisfied: pycparser in ./.eggs/pycparser-2.21-py3.10.egg (from cffi<2.0.0,>=1.14.2->pqcrypto) (2.21)
And running pip show pqcrypto produces this:
$ pip show pqcrypto
Name: pqcrypto
Version: 0.1.3
Summary: Post-quantum cryptography for Python.
Home-page: https://github.com/kpdemetriou/pqcrypto
Author: Phil Demetriou
Author-email: inbox@philonas.net
License:
Location: /home/mack/Desktop/RSAvsCK/venv/lib/python3.10/site-packages/pqcrypto-0.1.3-py3.10-linux-x86_64.egg
Requires: cffi
Required-by:
I have tried this in and without a virtual environment, but that's not to say I did not make a mistake in either process. Thanks much.
Installation of pqcrypto is not as simple as a pip install command despite it saying so in pypi.
See the official libpqcrypto website here: https://libpqcrypto.org/install.html
Installation commands are as follows, note you must be the root user so sudo is omitted here.
gcc and other compiler tools:
apt install build-essential`
OpenSSL header files:
apt install libssl-dev`
GMP header files:
apt install libgmp-dev
In a root terminal, create a libpqcrypto user:
adduser --disabled-password --gecos libpqcrypto libpqcrypto
Run a shell as that user:
su - libpqcrypto
As that user, download and unpack the latest version of libpqcrypto:
wget -m https://libpqcrypto.org/libpqcrypto-latest-version.txt
version=$(cat libpqcrypto.org/libpqcrypto-latest-version.txt)
wget -m https://libpqcrypto.org/libpqcrypto-$version.tar.gz
tar -xzf libpqcrypto.org/libpqcrypto-$version.tar.gz
cd libpqcrypto-$version
ln -s $HOME link-build
ln -s $HOME link-install
Compile, test, and install (this takes time):
./do
Exit the user shell:
exit