Pep 517 как исправить

I am trying to install a package which uses PEP 517. The newest version of Pip won’t allow me to install due to an error involving wheel building for 517.

In the past, I’ve solved this issue by downgrading Pip, installing the package and Upgrading Pip back to the latest version. However, after I downgrade pip in my virtualenv, if I try to run ‘Pip install black’ I get the No module named ‘pip._internal.cli.main’ error.

How can I solve this?

Mad Physicist's user avatar

Mad Physicist

106k25 gold badges180 silver badges261 bronze badges

asked Sep 24, 2020 at 2:22

Sean Payne's user avatar

4

The easiest solution to deal with the error

"Could not build wheels for ____ which use PEP 517 and cannot be installed directly" 

is the following:

sudo pip3 install _____ --no-binary :all:

Where ____ is obviously the name of the library you want to install.

answered Sep 24, 2020 at 3:50

Sean Payne's user avatar

Sean PayneSean Payne

1,5651 gold badge6 silver badges19 bronze badges

4

This solution from this link helped me:

pip install --upgrade pip setuptools wheel

answered Jun 27, 2022 at 22:47

Joel Oduro-Afriyie's user avatar

Sometimes this can be due to a cache issue and the no-binary flag won’t work. In which case try pip install <insert package names> --no-cache-dir.

This seems to be a frequent issue when installing packages with python. First, check to ensure you have activated the virtualenv you think you’re supposed to be in, then check to see if you have wheels pkg (pip install wheel if not). If those fail then the –no-cache-dir or –no-binary flags come into play. Reading the pypi documentation on each package could help as well. Best of luck!

answered May 7, 2021 at 20:27

KevinG's user avatar

KevinGKevinG

1092 silver badges5 bronze badges

Posting an answer as reference for future searchers here.

I tried installing Pillow and got this error. Tried many different approaches, none of them worked.
Then i downgraded Python (From 3.9) to 3.8 and just tried installing by pip again, then it worked.

If it fails for you, try downgrading Python, and it may work.

answered Dec 9, 2020 at 14:46

Alexander Santos's user avatar

2

When I ran into this error, the problem was that the package I was pulling had its metadata configured incorrectly, which caused building the wheels to fail.

To find that error I ran, pip --verbose install <my_package> Which let me see what about the wheel build was failing, and fix it upstream.

answered Jul 22, 2021 at 6:05

o0lemon_pie0o's user avatar

0

try this:
pip3 install –upgrade pip

answered Mar 17 at 17:19

Leonardo's user avatar

On OSX setting SYSTEM_VERSION_COMPAT=1 in my environment prior to running pip solved it:

export SYSTEM_VERSION_COMPAT=1

answered Apr 26, 2022 at 11:17

Christopher Broderick's user avatar

I have also encountered the same issue when uninstalling and reinstalling miniconda.

I have no idea why, but in my registry key ComputerHKEY_CURRENT_USERSOFTWAREMicrosoftCommand Processor AutoRun has been set to if exist. I deleted the value then it worked fine just as before.

person_v1.32's user avatar

person_v1.32

2,5511 gold badge13 silver badges26 bronze badges

answered Sep 9, 2021 at 2:38

yubari's user avatar

I am building a library that follows standard practices when it comes to development, testing and release (using tox and pytest, setup.cfg, etc). Sometime this morning, I suddenly started getting the following error when I attempt to run my tests and I am stumped as to the root cause.

Building wheels for collected packages: python-step-series
  Building wheel for python-step-series (PEP 517): started
  Building wheel for python-step-series (PEP 517): finished with status 'done'
  Created wheel for python-step-series: filename=python_step_series-0.0.2.dev1.post1.dev0_g1f5fc90.d20211206-py3-none-any.whl size=17943 sha256=6db044ba1828101d1ecd7f27be55a42b63711d537a6ea01d4935eaa4122655ef
  Stored in directory: /home/user/.cache/pip/wheels/46/6f/be/601a51d80e3889cae97cbe8b1a98cc4be1004f1e97546d94ef
  WARNING: Built wheel for python-step-series is invalid: Metadata 1.2 mandates PEP 440 version, but '0.0.2.dev1.post1.dev0-g1f5fc90.d20211206' is not
Failed to build python-step-series
ERROR: Could not build wheels for python-step-series which use PEP 517 and cannot be installed directly

I know it has something to do with git tagging and the fact that my working tree is dirty, but how to fix this is beyond me. Until this morning, I never had an issue. Creating a new tag every time I want to run my tests (using tox) seems to band-aid this–until my working tree becomes dirty again. Regardless, this band-aid isn’t efficient nor proper.

I’m using tox-conda instead of virtualenv, but each environment is reporting Pip version: 21.2.4 (python 3.7,3.8, 3.9. 3.10)

Has anyone else encountered or have knowledge of this issue and how to fix it?

  • I am on the latest Poetry version.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

  • OS version and name: Ubuntu 22.0.1

  • Poetry version: 1.2.0

  • Link of a Gist with the contents of your pyproject.toml file: pyproject.toml

Issue

A dependency uses MarkupSafe and our project must support python ^3.6.2. Since I updated to poetry 1.2.0, I can not use the python 3.6 environment anymore.

Installing MarkupSafe manually works, when I disable pep 517:

> poetry run python -m pip install --no-use-pep517 markupSafe==2.0.1

However, there is no option to disable pep 517 in poetry.
Is there any other way to install such packages?

Errors

> poetry env use 3.6
> poetry -vvv install
Using virtualenv: /tmp/foo/.venv
Project environment contains an empty path in sys_path, ignoring.
Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 1 install, 0 updates, 0 removals

  • Installing markupsafe (2.0.1): Pending...
Creating new session for pypi.org
  • Installing markupsafe (2.0.1): Installing...
  • Installing markupsafe (2.0.1): Failed

  Stack trace:

  2  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/utils/env.py:1469 in _run
      1467│                 )
      1468│             else:
    → 1469│                 output = subprocess.check_output(
      1470│                     command, stderr=subprocess.STDOUT, env=env, **kwargs
      1471│                 )

  1  /usr/lib/python3.10/subprocess.py:420 in check_output
       418│         kwargs['input'] = empty
       419│ 
    →  420│     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
       421│                **kwargs).stdout
       422│ 

  CalledProcessError

  Command '['/tmp/foo/.venv/bin/python', '/home/john/.local/share/pypoetry/venv/lib/python3.10/site-packages/virtualenv/seed/wheels/embed/pip-21.3.1-py3-none-any.whl/pip', 'install', '--use-pep517', '--disable-pip-version-check', '--prefix', '/tmp/foo/.venv', '--no-deps', '/home/local/.cache/pypoetry/artifacts/09/a9/a6/7e309619221c03e9a693897779a3fa9b06b4c71edb005b6919654585d3/MarkupSafe-2.0.1.tar.gz']' returned non-zero exit status 1.

  at /usr/lib/python3.10/subprocess.py:524 in run
       520│             # We don't call process.wait() as .__exit__ does that for us.
       521│             raise
       522│         retcode = process.poll()
       523│         if check and retcode:
    →  524│             raise CalledProcessError(retcode, process.args,
       525│                                      output=stdout, stderr=stderr)
       526│     return CompletedProcess(process.args, retcode, stdout, stderr)
       527│ 
       528│ 

The following error occurred when trying to handle this error:


  Stack trace:

  3  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/utils/pip.py:49 in pip_install
       47│ 
       48│     try:
    →  49│         return environment.run_pip(*args)
       50│     except EnvCommandError as e:
       51│         raise PoetryException(f"Failed to install {path.as_posix()}") from e

  2  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/utils/env.py:1433 in run_pip
      1431│         cmd = pip + list(args)
      1432│ 
    → 1433│         return self._run(cmd, **kwargs)
      1434│ 
      1435│     def run_python_script(self, content: str, **kwargs: Any) -> int | str:

  1  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/utils/env.py:1722 in _run
      1720│     def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
      1721│         kwargs["env"] = self.get_temp_environ(environ=kwargs.get("env"))
    → 1722│         return super()._run(cmd, **kwargs)
      1723│ 
      1724│     def get_temp_environ(

  EnvCommandError

  Command ['/tmp/foo/.venv/bin/python', '/home/local/.local/share/pypoetry/venv/lib/python3.10/site-packages/virtualenv/seed/wheels/embed/pip-21.3.1-py3-none-any.whl/pip', 'install', '--use-pep517', '--disable-pip-version-check', '--prefix', '/tmp/foo/.venv', '--no-deps', '/home/local/.cache/pypoetry/artifacts/09/a9/a6/7e309619221c03e9a693897779a3fa9b06b4c71edb005b6919654585d3/MarkupSafe-2.0.1.tar.gz'] errored with the following return code 1, and output: 
  Looking in indexes: https://pypi.org/simple, 
  Processing /home/local/.cache/pypoetry/artifacts/09/a9/a6/7e309619221c03e9a693897779a3fa9b06b4c71edb005b6919654585d3/MarkupSafe-2.0.1.tar.gz
    Installing build dependencies: started
    Installing build dependencies: finished with status 'done'
    Getting requirements to build wheel: started
    Getting requirements to build wheel: finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /tmp/foo/.venv/bin/python /home/local/.local/share/pypoetry/venv/lib/python3.10/site-packages/virtualenv/seed/wheels/embed/pip-21.3.1-py3-none-any.whl/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpkvyouqoq
         cwd: /tmp/pip-req-build-80e95xhl
    Complete output (1 lines):
    /tmp/foo/.venv/bin/python: can't find '__main__' module in '/home/local/.local/share/pypoetry/venv/lib/python3.10/site-packages/virtualenv/seed/wheels/embed/pip-21.3.1-py3-none-any.whl/pip/_vendor/pep517/in_process/_in_process.py'
    ----------------------------------------
  WARNING: Discarding file:///home/local/.cache/pypoetry/artifacts/09/a9/a6/7e309619221c03e9a693897779a3fa9b06b4c71edb005b6919654585d3/MarkupSafe-2.0.1.tar.gz. Command errored out with exit status 1: /tmp/foo/.venv/bin/python /home/local/.local/share/pypoetry/venv/lib/python3.10/site-packages/virtualenv/seed/wheels/embed/pip-21.3.1-py3-none-any.whl/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpkvyouqoq Check the logs for full command output.
  ERROR: Command errored out with exit status 1: /tmp/foo/.venv/bin/python /home/local/.local/share/pypoetry/venv/lib/python3.10/site-packages/virtualenv/seed/wheels/embed/pip-21.3.1-py3-none-any.whl/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpkvyouqoq Check the logs for full command output.
  

  at ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/utils/env.py:1473 in _run
      1469│                 output = subprocess.check_output(
      1470│                     command, stderr=subprocess.STDOUT, env=env, **kwargs
      1471│                 )
      1472│         except CalledProcessError as e:
    → 1473│             raise EnvCommandError(e, input=input_)
      1474│ 
      1475│         return decode(output)
      1476│ 
      1477│     def execute(self, bin: str, *args: str, **kwargs: Any) -> int:

The following error occurred when trying to handle this error:


  Stack trace:

  5  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:250 in _execute_operation
      248│ 
      249│             try:
    → 250│                 result = self._do_execute_operation(operation)
      251│             except EnvCommandError as e:
      252│                 if e.e.returncode == -2:

  4  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:323 in _do_execute_operation
      321│             return 0
      322│ 
    → 323│         result: int = getattr(self, f"_execute_{method}")(operation)
      324│ 
      325│         if result != 0:

  3  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:443 in _execute_install
      441│ 
      442│     def _execute_install(self, operation: Install | Update) -> int:
    → 443│         status_code = self._install(operation)
      444│ 
      445│         self._save_url_reference(operation)

  2  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:485 in _install
      483│         )
      484│         self._write(operation, message)
    → 485│         return self.pip_install(archive, upgrade=operation.job_type == "update")
      486│ 
      487│     def _update(self, operation: Install | Update) -> int:

  1  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:120 in pip_install
      118│     ) -> int:
      119│         try:
    → 120│             pip_install(req, self._env, upgrade=upgrade, editable=editable)
      121│         except EnvCommandError as e:
      122│             output = decode(e.e.output)

  PoetryException

  Failed to install /home/local/.cache/pypoetry/artifacts/09/a9/a6/7e309619221c03e9a693897779a3fa9b06b4c71edb005b6919654585d3/MarkupSafe-2.0.1.tar.gz

  at ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/utils/pip.py:51 in pip_install
       47│ 
       48│     try:
       49│         return environment.run_pip(*args)
       50│     except EnvCommandError as e:
    →  51│         raise PoetryException(f"Failed to install {path.as_posix()}") from e
       52│ 
  • Solutions
    • [1] Try to install Argon2-CFFI separately
    • [2] If it doesn’t work, make sure your PIP is updated to latest version
    • [3] Install xcode command line tools
      • [3.1] Error while xcode-select –install, reinstall command line tools
    • [4] Still failing with the same error
  • If it works, run jupyter notebook to verify
  • References


Figure: Terminal with error

While trying to install jupyter notebook in Mac OS with PIP (source)

You could get error message like:

ERROR: Could not build wheels for argon2-cffi which use PEP 517 and cannot be installed directly

In this article I have added the series of steps I tried and it’s possible the issue for you could be fixed with just of them (based on what the underlying issue is).

Solutions

[1] Try to install Argon2-CFFI separately

Argon2-CFFI is a secure password hashing algorithm. Try to install it separately:

If it works try to install jupyter notebook again. Most likely this will fail with the same error.

[2] If it doesn’t work, make sure your PIP is updated to latest version

pip install --upgrade pip --user

The installation worked for me after this step. But since I didn’t follow the steps in this order I found other solutions that worked for some other folks. Adding it here, in case it comes in handy.

[3] Install xcode command line tools

This command is used to install the command line developer tools. This should ideally open a popup and after the installation is complete, try running the notebook installation again.

[3.1] Error while xcode-select –install, reinstall command line tools

xcode-select --install could sometime fail with following error

$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Based on the SO answer for How to update Xcode from command line – the easiest way to do this would be to remove the old version of the tools and reinstall the new one.

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

A popup will open and it will take a bit of time to install the command line tools.


Figure: Popup while the command line tools are being reinstalled.

[4] Still failing with the same error

If you are still getting following error:

ERROR: Could not build wheels for argon2-cffi which use PEP 517 and cannot be installed directly

Per this you could try to install p5py and PEP517 directly.

pip install p5py
pip install PEP517

If this fails with

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/3.8'
Consider using the `--user` option or check the permissions.

Follow the advice:

pip install p5py --user
pip install PEP517 --user

If it works, run jupyter notebook to verify

It should run without error:


Figure: Successfully starting jupyter notebook from mac.

References

  1. Mac installation Jupyter Notebook error error: COULD NOT BUILD WHEELS for argon2-cffi Which USE PEP 517 and…
  2. How to update Xcode from command line
  3. ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly

Want to read more such similar contents?

If you found this article useful, please feel free to share feedbacks – it’s a great incentive to see happy readers. If you found some inaccurate information please report that as well – I’d be very happy to update and give you credits!

I like to write articles on topic less covered on internet. They revolve around writing fast algorithms, image processing as well as general software engineering.

I publish many of them on Medium.

If you are already on medium – Please join 4200+ other members and Subscribe to my articles to get updates as I publish.

If you are not on Medium – Medium has millions of amazing articles from 100K+ authors. To get access to those, please join using my referral link. This will give you access to all the benefits of Medium and Medium shall pay me a piece to support my writing!

Thanks!

Solution 1:[1]

I had the same problem and i did this,

pip install --upgrade pip setuptools wheel

then install opencv again,

pip install opencv-python

this worked for me

Solution 2:[2]

Yes .. Finally found a work around.
Follow this https://github.com/mdegans/nano_build_opencv and build from source and finally gets installed.

PS: It may take a bit long for building, for me it took 10 Hrs :P.

Happy Image-Processing..

Solution 3:[3]

If after

pip install --upgrade pip setuptools wheel

you still have the same error,

You can try to specify the older version of OpenCV to install.

Ex.

pip3 install opencv-python==3.4.13.47

Solution 4:[4]

I had a similar problem and what solved it for me was not to use python:3-alpine but python:3.8-slim. E.g.:

FROM python:3.8-slim
WORKDIR /usr/src/app

RUN apt update
RUN apt -y install build-essential libwrap0-dev libssl-dev libc-ares-dev uuid-dev xsltproc
RUN apt-get update -qq 
    && apt-get install --no-install-recommends --yes 
        build-essential 
        gcc 
        python3-dev 
        mosquitto 
        mosquitto-clients


RUN pip3 install --upgrade pip setuptools wheel

RUN python3 -m pip install --no-cache-dir 
      numpy scipy matplotlib scikit-build opencv-contrib-python-headless 
      influxdb paho-mqtt configparser Pillow 
      qrcode

worked finally for me.

Solution 5:[5]

please check your python specifications:


  - opencv -> python[
version='
>=2.7,<2.8.0a0
>=3.5,<3.6.0a0
>=3.6,<3.7.0a0
>=3.7,<3.8.0a0']

Solution 6:[6]

I handled it by reinstalling python3 from scratch in my MacBook:

brew reinstall [email protected]

I also reinstalled numpy and matplotlib packages experimentally.

pip3 install numpy
pip3 install matplotlib 
pip3 install opencv-contrib-python

The versions:

macOS Mojave 10.14.5
Python 3.9.7
OpenCV 4.5.3

OpenCV’s version is 4.5.3 by this way:

import cv2 
print(cv2.__version__)

But by “pip list”, it shows “opencv-contrib-python 3.4.9.31”.

Solution 7:[7]

if you are trying to install opencv in your raspberrypi 3B, Use following steps:

  1. sudo raspi-config
  2. advanced — expand filesystem
  3. reboot your pi

Open your raspi terminal and do following stuff:

  1. use command: sudo apt-get update
  2. use command: sudo apt-get upgrade
  3. check your python version and upgarde it to latest one
  4. install pip and upgrade pip
  5. use command: mkdir project
  6. use command: cd project
  7. create virtual environment
  8. activate virtual environment
  9. install dependencies ,can get dependencies from https://singleboardbytes.com/647/install-opencv-raspberry-pi-4.htm
  10. if error in installing libdhf5-dev
  11. use command: sudo apt-get install python3-h5py and reinstall libdhf5-dev
  12. use command: pip install scikit-build
  13. use command: pip install cython
  14. before installing opencv ,make sure you are in virtual environment or
    activate environment
  15. use command: pip install –no-cache-dir opencv-contrib-python==4.5.3.56
  16. Remember to use mentioned version…

Thank You…

Solution 8:[8]

I came across similiar situation
I had error

Failed to build opencv-python ERROR: Could not build wheels for
opencv-python which use PEP 517 and cannot be installed directly
WARNING: You are using pip version 19.2.3, however version 22.0.4 is
available. You should consider upgrading via the ‘python -m pip
install –upgrade pip’ command.

I ran in command prompt with admin privileges following
python -m pip install –upgrade pip
Now “pip install opencv-python” works

Добавить комментарий