Cryptography: No module named 'setuptools_rust' with cryptography==3.4

Created on 7 Feb 2021  ยท  22Comments  ยท  Source: pyca/cryptography

EDIT: tl;dr: run "pip install --upgrade pip". You don't need to install Rust! Use --prefer-binary to make sure you're not rebuilding from sources.

$ python --version
Python 3.6.8
$ pip install cryptography
Collecting cryptography
  Downloading https://files.pythonhosted.org/packages/ea/d8/2afd2890fe451a3c109d2bdb6bc4ded55ec43059e524344d5e0004e36412/cryptography-3.4.tar.gz (544kB)
    100% |โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 552kB 2.1MB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-zb4wktwf/cryptography/setup.py", line 13, in <module>
        from setuptools_rust import RustExtension
    ModuleNotFoundError: No module named 'setuptools_rust'

"cryptography<3.4"
works just fine. Anything I am doing wrong ?

installation

Most helpful comment

I'm using pip 21.0.1 (Python 3.8) on Ubuntu 18.04, and I'm still getting this error. I pinned cryptography to 3.3 for now.

All 22 comments

What version of pip are you using?

pip 9.0.3 :/ .. the default with centos7

upgrading to pip-21.0.1 fixes the problem :) thanks for the hint. If there is a way to report the error cleanly or force upgrade of pip that would be ideal. Closing anyway.

I'll see about improving the error message, good idea.

Thanks for the workaround. In addition to CentOS 7 mentioned in https://github.com/pyca/cryptography/issues/5753#issuecomment-774753108, Ubuntu 18.04 currently ships Python 3.6/pip 9.0.1 by default so I suspect more installation workflows might be broken by the latest release unless they upgrade pip

Adding :+1: for ideally some mechanism detecting the pip version and minimally some message suggesting to upgrade pip.

The next build failed with ci / cd. Began to check and saw that the version had changed for cryptography 3.3.2 -> 3.4
It runs in docker:19.03.1-dind

pip3 install docker-compose
...

   error: Can not find Rust compiler
   ----------------------------------------
   ERROR: Failed building wheel for cryptography

https://cryptography.io/en/latest/faq.html#installing-cryptography-fails-with-error-can-not-find-rust-compiler

https://cryptography.io/en/latest/faq.html#installing-cryptography-fails-with-error-can-not-find-rust-compiler

You will need to change https://cryptography.io/en/latest/installation.html#alpine and add

apk add rust cargo

this work for me

apk add rust cargo

https://cryptography.io/en/latest/faq.html#installing-cryptography-fails-with-error-can-not-find-rust-compiler

You will need to change https://cryptography.io/en/latest/installation.html#alpine and add

apk add rust cargo

this work for me

Not me - I'm seeing this now:

#64 119.1        Running `rustc --crate-name pyo3_macros_backend --edition=2018 /root/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-macros-backend-0.13.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C metadata=1c47d36fb0c032da -C extra-filename=-1c47d36fb0c032da --out-dir /tmp/pip-install-hkvurqop/cryptography_b5ee5dd617e44d6cb4f77b54ca25070a/src/rust/target/release/deps -L dependency=/tmp/pip-install-hkvurqop/cryptography_b5ee5dd617e44d6cb4f77b54ca25070a/src/rust/target/release/deps --extern proc_macro2=/tmp/pip-install-hkvurqop/cryptography_b5ee5dd617e44d6cb4f77b54ca25070a/src/rust/target/release/deps/libproc_macro2-aa3871282eef8eab.rmeta --extern quote=/tmp/pip-install-hkvurqop/cryptography_b5ee5dd617e44d6cb4f77b54ca25070a/src/rust/target/release/deps/libquote-4a1344d16195b0c6.rmeta --extern syn=/tmp/pip-install-hkvurqop/cryptography_b5ee5dd617e44d6cb4f77b54ca25070a/src/rust/target/release/deps/libsyn-e836c33ca097f1fb.rmeta --cap-lints allow -C target-feature=-crt-static`
#64 119.1   error[E0658]: use of unstable library feature 'str_strip': newly added
#64 119.1      --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-macros-backend-0.13.1/src/method.rs:144:18
#64 119.1       |
#64 119.1   144 |                 .strip_prefix(prefix)
#64 119.1       |                  ^^^^^^^^^^^^
#64 119.1       |
#64 119.1       = note: see issue #67302 <https://github.com/rust-lang/rust/issues/67302> for more information
#64 119.1   
#64 119.1   error: aborting due to previous error
#64 119.1   
#64 119.1   For more information about this error, try `rustc --explain E0658`.
#64 119.1   error: could not compile `pyo3-macros-backend`.

I'm swimming in build failures on various platforms caused by this at the moment, so any hints to save me time tracking them all down individually would be appreciated!

You need latest Alpine with Rust >= 1.45.

Thanks - yeah, I needed to update to 3.13.

the same with 3.4.1

Collecting cryptography>=2.0 (from SecretStorage>=3.2; sys_platform == "linux"->keyring>=15.1->twine==3.1.1->-r /root/project/requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/06/ed/cb79cc94ec58d9d92557238fc6c629cd6e07d72334d2de556aecc2211370/cryptography-3.4.1.tar.gz (544kB)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-h9s3g3of/cryptography/setup.py", line 14, in <module>
        from setuptools_rust import RustExtension
    ModuleNotFoundError: No module named 'setuptools_rust'

            =============================DEBUG ASSISTANCE==========================
            If you are seeing an error here please try the following to
            successfully install cryptography:

            Upgrade to the latest pip and try again. This will fix errors for most
            users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
            =============================DEBUG ASSISTANCE==========================


    ----------------------------------------
 (Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-h9s3g3of/cryptography/
)

@stamak your pip version is too old.

https://cryptography.io/en/latest/faq.html#installing-cryptography-fails-with-error-can-not-find-rust-compiler

You will need to change https://cryptography.io/en/latest/installation.html#alpine and add

apk add rust cargo

this work for me

What I've attempted (from python:3.7.5-alpine):

  1. pip install --upgrade pip setuptools
  2. sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo - tried both libressl-dev and openssl-dev
  3. pip install cryptography --no-binary cryptography

The no Rust compiler is fixed but another one pops up.

running build_rust
  error: failed to parse lock file at: /tmp/pip-install-2ndtenxi/cryptography_82df3bbc5d0b43f79d507ec6c448c7ff/src/rust/Cargo.lock

  Caused by:
running build_ext
  generating cffi module 'build/temp.linux-x86_64-3.7/_padding.c'
  creating build/temp.linux-x86_64-3.7
  generating cffi module 'build/temp.linux-x86_64-3.7/_openssl.c'
  running build_rust
  error: failed to parse lock file at: /tmp/pip-install-2ndtenxi/cryptography_82df3bbc5d0b43f79d507ec6c448c7ff/src/rust/Cargo.lock

  Caused by:
    invalid serialized PackageId for key `package.dependencies`

      =============================DEBUG ASSISTANCE=============================
      If you are seeing a compilation error please try the following steps to
      successfully install cryptography:
      1) Upgrade to the latest pip and try again. This will fix errors for most
         users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
      2) Read https://cryptography.io/en/latest/installation.html for specific
         instructions for your platform.
      3) Check our frequently asked questions for more information:
         https://cryptography.io/en/latest/faq.html
      4) Ensure you have a recent Rust toolchain installed.
      =============================DEBUG ASSISTANCE=============================

Why is a new pip version required? For example, we use pip 9.0.1 and are installing paramiko==2.2.2 results in this issue. (paramiko sets a >= dependency) - please understand this has a significant impact.

Why is a new pip version required? For example, we use pip 9.0.1 and are installing paramiko==2.2.2 results in this issue. (paramiko sets a >= dependency) - please understand this has a significant impact.

You need a more recent pip version that supports pyproject.toml. IIRC pip 19.1.1 is the oldest version that works.

I'm using pip 21.0.1 (Python 3.8) on Ubuntu 18.04, and I'm still getting this error. I pinned cryptography to 3.3 for now.

Can you share some instructions to reproduce?

On Mon, Feb 8, 2021 at 12:48 PM John Velonis notifications@github.com
wrote:

I'm using pip 21.0.1 (Python 3.8) on Ubuntu 18.04, and I'm still getting
this error. I pinned cryptography to 3.3 for now.

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/pyca/cryptography/issues/5753#issuecomment-775324788,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAAGBETUGTS3ZVG3RQHUZLS6APYNANCNFSM4XHZOHNA
.

--
All that is necessary for evil to succeed is for good people to do nothing.

My build uses Packer to create a container image based on the stock ubuntu:bionic image. It runs the following as root:

#!/bin/bash -ex

PYTHON_VERSION=3.8
export DEBIAN_FRONTEND=noninteractive

apt-get -y update
apt-get -y upgrade

apt-get install -y python${PYTHON_VERSION}
apt-get install -y python3-pip

# Make sure we have the latest pip (the package may be out of date)
python${PYTHON_VERSION} -m pip install -U pip
pip3 --version

apt-get install -y python${PYTHON_VERSION}-venv

mkdir /app
cp requirements.txt /app/requirements.txt

# Install the libraries in a virtual environment
cd /app
python${PYTHON_VERSION} -m venv .venv
source .venv/bin/activate
pip3 install -r /app/requirements.txt

The problem is almost certainly that you have a different pip inside your
virtualenv than you do outside of it. Try adding a pip3 install -U pip
right after your source the venv.

On Mon, Feb 8, 2021 at 1:17 PM John Velonis notifications@github.com
wrote:

My build uses Packer to create a container image based on the stock
ubuntu:bionic image. It runs the following as root:

!/bin/bash -ex

PYTHON_VERSION=3.8
export DEBIAN_FRONTEND=noninteractive

apt-get -y update
apt-get -y upgrade

apt-get install -y python${PYTHON_VERSION}
apt-get install -y python3-pip

Make sure we have the latest pip (the package may be out of date)

python${PYTHON_VERSION} -m pip install -U pip
pip3 --version

apt-get install -y python${PYTHON_VERSION}-venv

mkdir /app
cp requirements.txt /app/requirements.txt

Install the libraries in a virtual environment

cd /app
python${PYTHON_VERSION} -m venv .venv
source .venv/bin/activate
pip3 install -r /app/requirements.txt

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/pyca/cryptography/issues/5753#issuecomment-775343294,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAAGBHTR44CWH7QCUDGW33S6ATDBANCNFSM4XHZOHNA
.

--
All that is necessary for evil to succeed is for good people to do nothing.

That did it, thanks!

That did it, thanks!

You may also switch to virtualenv instead of venv - this will installed the latest pip inside as well.

For anyone else running into this same issue, for whom updating pip is not enough, here's what worked for me. While installing cryptography on a Debian 10 Buster docker container, I also had to upgrade setuptools (40.8.0 -> 56.0.0), so the command that fixed my issues was:

python3 -m pip install -U pip setuptools

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clarius-deploy picture clarius-deploy  ยท  22Comments

mhils picture mhils  ยท  28Comments

abhishek-ram picture abhishek-ram  ยท  37Comments

chitoge picture chitoge  ยท  26Comments

Naddiseo picture Naddiseo  ยท  45Comments