191

I'm trying to install scipy via pip on my 64 bit ARMV8 board. I have already installed openblas which is required by scipy. So, no issues with that. When i gave pip3 install scipy --trusted-host pypi.org --trusted-host files.pythonhosted.org , I got the error Failed building wheel for scipy . I have pip3 and pip3.5 in my /usr/bin and the rest of the pip is in /usr/lib64/python3.5/site-packages.So basically, I also have pip.

I also tried to install scipy with --no-binary option, which was one of the answers on net. But, it gave me the same error. Below's the error that i got.

ERROR:

Collecting scipy
  Downloading scipy-1.4.1.tar.gz (24.6 MB)
     |################################| 24.6 MB 6.6 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: scipy
  Building wheel for scipy (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /usr/lib64/python3.5/site-packages/pip-20.0.2-py3.5.egg/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmpkklsvv4v
       cwd: /tmp/pip-install-9v4nmof7/scipy
  Complete output (50 lines):
  /usr/bin/python3: No module named pip
  Traceback (most recent call last):
    File "/usr/lib64/python3.5/site-packages/setuptools/installer.py", line 128, in fetch_build_egg
      subprocess.check_call(cmd)
    File "/usr/lib64/python3.5/subprocess.py", line 271, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmpp7fvgp36', '--quiet', 'numpy>=1.13.3']' returned non-zero exit status 1

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/usr/lib64/python3.5/site-packages/pip-20.0.2-py3.5.egg/pip/_vendor/pep517/_in_process.py", line 257, in <module>
      main()
    File "/usr/lib64/python3.5/site-packages/pip-20.0.2-py3.5.egg/pip/_vendor/pep517/_in_process.py", line 240, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/usr/lib64/python3.5/site-packages/pip-20.0.2-py3.5.egg/pip/_vendor/pep517/_in_process.py", line 182, in build_wheel
      metadata_directory)
    File "/usr/lib64/python3.5/site-packages/setuptools/build_meta.py", line 213, in build_wheel
      wheel_directory, config_settings)
    File "/usr/lib64/python3.5/site-packages/setuptools/build_meta.py", line 198, in _build_with_temp_dir
      self.run_setup()
    File "/usr/lib64/python3.5/site-packages/setuptools/build_meta.py", line 250, in run_setup
      self).run_setup(setup_script=setup_script)
    File "/usr/lib64/python3.5/site-packages/setuptools/build_meta.py", line 143, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 540, in <module>
      setup_package()
    File "setup.py", line 536, in setup_package
      setup(**metadata)
    File "/usr/lib64/python3.5/site-packages/numpy/distutils/core.py", line 126, in setup
      dist = setup(**new_attr)
    File "/usr/lib64/python3.5/site-packages/numpy/distutils/core.py", line 169, in setup
      return old_setup(**new_attr)
    File "/usr/lib64/python3.5/site-packages/setuptools/__init__.py", line 143, in setup
      _install_setup_requires(attrs)
    File "/usr/lib64/python3.5/site-packages/setuptools/__init__.py", line 138, in _install_setup_requires
      dist.fetch_build_eggs(dist.setup_requires)
    File "/usr/lib64/python3.5/site-packages/setuptools/dist.py", line 698, in fetch_build_eggs
      replace_conflicting=True,
    File "/usr/lib64/python3.5/site-packages/pkg_resources/__init__.py", line 783, in resolve
      replace_conflicting=replace_conflicting
    File "/usr/lib64/python3.5/site-packages/pkg_resources/__init__.py", line 1066, in best_match
      return self.obtain(req, installer)
    File "/usr/lib64/python3.5/site-packages/pkg_resources/__init__.py", line 1078, in obtain
      return installer(requirement)
    File "/usr/lib64/python3.5/site-packages/setuptools/dist.py", line 754, in fetch_build_egg
      return fetch_build_egg(self, req)
    File "/usr/lib64/python3.5/site-packages/setuptools/installer.py", line 130, in fetch_build_egg
      raise DistutilsError(str(e))
  distutils.errors.DistutilsError: Command '['/usr/bin/python3', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmpp7fvgp36', '--quiet', 'numpy>=1.13.3']' returned non-zero exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for scipy
Failed to build scipy
ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly
Sourabrt
  • 2,126
  • 2
  • 8
  • 22
  • `/usr/bin/python3 --version`? `/usr/bin/python3 -m pip --version`? – phd Apr 22 '20 at 14:34
  • @phd: `/usr/bin/python3 --version` is **Python 3.5.3** and `/usr/bin/python3 -m pip --version` says **no module named pip**. – Sourabrt Apr 23 '20 at 05:25
  • 1
    You need to [install `pip`](https://pip.pypa.io/en/stable/installing/) – phd Apr 23 '20 at 08:43
  • @phd: I already have pip installed. `/usr/bin/pip3 --version` gives **pip 20.0.2 from /usr/lib64/python3.5/site-packages/pip-20.0.2-py3.5.egg/pip (python 3.5)** – Sourabrt Apr 23 '20 at 10:07
  • "*`/usr/bin/python3 -m pip --version` says **no module named pip**.*" means you don't have `pip` installed or `/usr/bin/python3` doesn't know where to find it. `/usr/bin/python3 -c "import sys; print(sys.path)"` — is `/usr/lib64/python3.5/site-packages` in the list? – phd Apr 23 '20 at 10:10
  • @phd: yes it is. It gives this - `['', '/usr/lib/python35.zip', '/usr/lib64/python3.5', '/usr/lib64/python3.5/plat-linux', '/usr/lib64/python3.5/lib-dynload', '/usr/lib64/python3.5/site-packages']` . As you can see there's `/usr/lib64/python3.5/site-packages` – Sourabrt Apr 23 '20 at 10:27
  • Hmm, `/usr/lib64/python3.5/site-packages` is in `sys.path` but not `/usr/lib64/python3.5/site-packages/pip-20.0.2-py3.5.egg/`. Strange configuration. Are you sure `/usr/bin/python3` and `/usr/bin/python3.5` are the same Python? `/usr/bin/python3.5 -m pip --version`? `head -1 /usr/bin/pip3`? `head -1 /usr/bin/pip3.5`? – phd Apr 23 '20 at 10:33
  • @phd: Yes. Both are same. `/usr/bin/python3.5 -m pip --version` says `/usr/bin/python3.5: No module named pip` and `head -1 /usr/bin/pip3` says `#!/usr/bin/env python3` and `head -1 /usr/bin/pip3.5` says `#!/usr/bin/env python3`. – Sourabrt Apr 23 '20 at 10:37

30 Answers30

206

I had the same issue with opencv-python. What worked for me was updating pip as:

pip3 install --upgrade pip

Note: I am using docker on Linux.

Ahmed Ktob
  • 2,874
  • 1
  • 11
  • 15
80

I had the same issue. I resolved this issue after run below command

pip install --upgrade pip setuptools wheel
fcdt
  • 2,371
  • 5
  • 14
  • 26
Bharat Kumar
  • 837
  • 6
  • 3
  • 23
    This did not work on Python `3.9.4`, pip `pip 21.0.1`, macOS Big Sur `11.2.3 (20D91)` when attempting to install scipy `1.6.2`. Still getting same error original question – Greg Hilston Apr 08 '21 at 13:26
  • 4
    READ YOUR ERROR OUTPUT! This should be the go-to answer for this question - since it allows package manager to handle appropriately. If it still fails, it is probably because you are only reading the last line of the error message. For myself, I was stuck with an application running python2.7 (business) and had to install the python2-dev (older version) due to Python.h header file not matching for version pointer. – Elysiumplain May 06 '21 at 18:30
  • I still got error error: Unable to invoke pkg-config – bjm88 Jul 06 '21 at 02:04
  • @GregHilston what is the solution for python 3.9 ?? I am also facing same issue – user9920500 Jul 10 '23 at 15:15
  • @user9920500 I'm unsure ha this was 2 years ago :) – Greg Hilston Jul 18 '23 at 18:44
32

My problem was not with scipy, but with xmlsec. The error message was almost the same:

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

I needed this library, because it was dependency for python3-saml. From the documentation I read that they first install these packages:

sudo apt-get install libxml2-dev libxmlsec1-dev

After doing this the installation of python3-saml worked for me.

pip3 -V
pip 20.2.3

python -V
Python 3.8.0b3

Probably the answer for other libraries is different, but they all need some package in order to be build, and you should find what is this package for you.

makkasi
  • 6,328
  • 4
  • 45
  • 60
  • 1
    I am on macOSx, so homebrew doesn't find libxml2-dev libxmlsec1-dev, tried brew install libxml2, didn't Help. Still get error: Unable to invoke pkg-config. ERROR: Could not build wheels for xmlsec which use PEP 517 and cannot be installed directly – bjm88 Jul 06 '21 at 02:07
  • @bjm88 This is not the problem for you since the libxml2 library comes with OS X. I am not quite aware of OS X, but may be you could try to find solution just to install libxml2-dev then. Look at this answer here: https://stackoverflow.com/questions/26473197/how-to-install-libxml2-dev-libxslt-dev-on-mac-os – makkasi Jul 06 '21 at 10:20
22

This error also comes for numpy and if you are using the new M1 chip, I am afraid you have to install packages like numpy differently. Check this out.

Bendemann
  • 735
  • 11
  • 31
  • I don't want to directly edit your answer for something resembling self-promotion... but if you can test this and confirm it works, sharing this might help other folks. I have been successful speeding up training on M1+GPU on TF 2.5. Here is my env: https://github.com/ctrahey/m1-tensorflow-config – Chris Trahey Aug 14 '21 at 18:29
10

directly do

pip install p5py
pip install PEP517

this will do the work.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Suniti Jain
  • 382
  • 2
  • 10
6

I faced the same problem. Seems that pip uses the pkg-config - if this is missing from your host OS it will run into this error. I resolved by:

sudo apt-get install -y pkg-config

Then re-run pip

Med Shah
  • 91
  • 1
  • 2
6

I had this issue trying to install the tidyms package (which depends on scipy <= 1.4.1).

In my case, using python 3.8 instead of python 3.9 "solved" the issue (at least was able to install).

bwv549
  • 5,243
  • 2
  • 23
  • 20
5

I was struggling to install pandas with Jupyter (Ubuntu) using the command pip install pandas:

Failed to build pandas ERROR: Could not build wheels for pandas which use PEP 517 and cannot be installed directly

Below was the solution for me:

pip install --upgrade pip setuptools wheel

then

pip install pandas -i https://pypi.mirrors.ustc.edu.cn/simple/
Zoe
  • 27,060
  • 21
  • 118
  • 148
4

In my case I was installing from a requirements.txt file with the command:

pip install -r requirements.txt

And was getting this error. I solved it installing the package individually (pip install scipy) and replacing the version of Scipy I had in requirements.txt with the one that worked.

Genarito
  • 3,027
  • 5
  • 27
  • 53
4

Had similar issues. I had to install some OS and after that, I was able to install missing scikit packages (scikit-sparse in my case)

sudo apt-get install libsuitesparse-dev
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Gadi
  • 76
  • 5
2

If using Windows OS, verify under Start > Settings > Update & Security > Windows Security > Virus & threat protection > Protection History if Windows is identifying the file for installing PyInstaller with Pip as potential malware and thus blocking it. Worked for me.

rzimmerdev
  • 89
  • 1
  • 9
2
ERROR: Failed building wheel for h5py
Failed to build h5py
ERROR: Could not build wheels for h5py which use PEP 517 and cannot be installed directly

I had a similar issue while installing Keras, resolved above issue using below steps:

  1. conda install h5py

  2. pip install keras

john-hen
  • 4,410
  • 2
  • 23
  • 40
Sunil
  • 21
  • 1
2

Try to install an order version. I had the same problem using python 3.10. I just downgrade it to python 3.9.7 and worked fine

Arthur
  • 99
  • 7
2

If you are using Mac, it could be because of the Xcode license agreement.
Try below in a terminal.

sudo xcodebuild -license

plhn
  • 5,017
  • 4
  • 47
  • 47
1

Personally I get rid of this error by changing the #!/usr/bin/env python3.9 to #!/usr/bin/env python3 in the file located in ~/.poetry/bin/poetry and running pip3 install --upgrade pip setuptools wheel apparently python3.9 got some difficulties with poetry.

1

This error ocurred for me while trying to pip3 install aws-sam-cli awscli on macOS 11.5.2 (M1 Chip).

Adding the follow two lines worked for me

dnf install -y python3-devel
dnf group install -y "Development Tools"

Full Dockerfile

FROM centos:8

RUN dnf upgrade -y && \
    dnf module -y install nodejs:14 && \
    dnf install -y python3 python3-devel git-all && \
    dnf group install -y "Development Tools" && \
    pip3 install --upgrade pip setuptools && \
    pip3 install aws-sam-cli awscli
1

for the latest M1 type of mac , before creating a virtualenv do switch zsh to x86 type

Step 1:

arch -x86_64 zsh
uname -m 

The output will be x86_64 which was arm64 earlier.

Step 2:

brew install openblas
export OPENBLAS=$(brew --prefix openblas)
export CFLAGS="-falign-functions=8 ${CFLAGS}"
pip install Cython pybind11 pythran
pip install --no-use-pep517 scipy

(no need after step 1 : --no-use-pep517 )

after that everything is normal

Upendra
  • 716
  • 9
  • 17
aryan singh
  • 151
  • 11
1

I had the same issue with Django Rest Framework on Docker (running on M1 Mac), and what worked for me was adding

RUN pip install --upgrade pip

just before I install all the project dependencies.

1

In my case, I just used a specific python version i.e 3.8 for my base image instead of latest

Before: FROM python:3

After: FROM python:3.8

Issue Resolved for me

1

i am using windows x64 based processor. still i havent found solution on this. i tried all above but not worked on me.

but yea after trying hundreds of times i found solution. i downgrade the python version from 3.10.0 to 3.8.10 and it is fine now

1

Simply installing the dependent failing package (in your case scipy) separately will fix the issue.

python3 -m pip install scipy

followed by pip installing the package you were trying in the first place.

1

if you are in the environment of conda, then you should use:

conda install scipy

cause conda will install all the dependencies necessary and make sure the building successful.

dwqy11
  • 125
  • 1
  • 1
  • 8
0

I had the same issue and solved it by installing the module using conda. In my case conda install -c conda-forge statsmodels worked without error.

Alireza
  • 87
  • 4
0

Try:

apt-get install build-essential python-dev python-pip

Then:

pip install couchbase
Nikhil MVS
  • 31
  • 1
  • 4
0

I ran into the same issue, albeit on an Apple M1 Macbook Pro. The solution in this case was to use Miniforge instead of Anaconda, because the latter doesn't support the arm64 architecture, yet.

martin_wun
  • 1,599
  • 1
  • 15
  • 33
0

The problem I was facing was that I upgraded to the next python version as soon as it was released.

Advice: wait for atleast 1-2 months before upgrading.

The different modules and libararies on the web aren't updated as soon as python update is released and hence they wont be compatible.

Simply downrade your python version to the version just before current one and you will be good to go.

No matter what you install or what you do you wont be able to install the module unless the devs update it.

0

I started getting this error after upgrading macOS to the latest version.

  • I had to re-install Xcode tools by running xcode-select --install first.

  • Close and re-open terminal window

And then, was able to install pandas without any issues.

gip
  • 113
  • 1
  • 9
0

My issue was with mpi4py. My pip install generated this error, but installing the package through the Anaconda GUI did the trick.

Clayton C.
  • 863
  • 1
  • 8
  • 17
0

Try

pip install --pre --extra-index https://pypi.anaconda.org/scipy-wheels-nightly/simple scikit-learn

for Python version 3.10 or greater.

0

I faced similiar problem while installing pycocotools. This answer is for anyone who tried to install pycocotools but faced the similar type of problem while installing.

Try using this instead:

pip install pycocotools-windows

If you are using conda environment, use this as well:

conda install cython
Prakash Dahal
  • 4,388
  • 2
  • 11
  • 25