Andy Peng
Andy Peng

Reputation: 119

How do I fix setuptools not available in build environment when trying to install libraries in python?

I'm trying to install a requirements.txt file in Docker, and I make it about 30 packages in when I get this error when trying to install importlib:

Can not execute setup.py since setuptools is not available in the build environment.

Here is the full error message:

Collecting importlib==1.0.4
#9 14.42   Downloading importlib-1.0.4.zip (7.1 kB)
#9 14.43   Preparing metadata (setup.py): started
#9 14.45   Preparing metadata (setup.py): finished with status 'error'
#9 14.45   error: subprocess-exited-with-error
#9 14.45   
#9 14.45   × python setup.py egg_info did not run successfully.
#9 14.45   │ exit code: 1
#9 14.45   ╰─> [1 lines of output]
#9 14.45       ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
#9 14.45       [end of output]
#9 14.45   
#9 14.45   note: This error originates from a subprocess, and is likely not a problem with pip.
#9 14.45 error: metadata-generation-failed
#9 14.45 
#9 14.45 × Encountered error while generating package metadata.
#9 14.45 ╰─> See above for output.
#9 14.45 
#9 14.45 note: This is an issue with the package mentioned above, not pip.
#9 14.45 hint: See above for details.

In the Dockerfile, I have tried installing setuptools before installing the packages:

RUN python3 -m pip install setuptools
RUN python3 -m pip install -r requirements.txt

Some further details: my python version is 3.9, pip version is 22.1.2

When I do

easy_install --version

, I get

setuptools 41.0.1 from /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (Python 2.7)

However, when I try to install setuptools with pip, it says I have version 62.3.3 for python3.9

Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (62.3.3)

Any help is greatly appreciated, and let me know if I should provide any further details.

Upvotes: 9

Views: 38296

Answers (2)

Zabih ullah
Zabih ullah

Reputation: 31

I was facing the same issue. My issue is resolved when I install these versions.

python -m pip install pip==21.3.1

pip install setuptools==57.5.0

Upvotes: 3

flomaster
flomaster

Reputation: 1813

As mentioned in the comments, the error appears because you are trying to install importlib on Python 3.9, while it's meant for much older Python versions only.

Just remove importlib from your requirements.txt file.

Upvotes: 9

Related Questions