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

2

9

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.

Revolutionize answered 10/6, 2022 at 8:0 Comment(3)
Why is it trying to install importlib? importlib is part of Python's standard library, so it should always be available without needing to install it from PyPI with pip. -- To be accurate there is an importlib on PyPI but it is meant only for very old versions of Python that do not have importlib out of the box.Philomena
It means one of the dependencies only works on python2Cremona
I'm here because I just installed pandas and the Excel reader fails in importlib: File ~/DataScience/venv/lib/python3.10/site-packages/pandas/compat/_optional.py:141, in import_optional_dependency(name, extra, errors, min_version) 140 try: --> 141 module = importlib.import_module(name) 142 except ImportError: and when I try 'pip install importlib' THAT fails on setuptools.Compliment
C
9

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.

Comatulid answered 6/7, 2022 at 13:36 Comment(2)
you may right. I am also facing problem installing Python 3.9 version. Needs lot of effort to install library such as pygrib, cfgrib, eccodes, basemap-data-hires, etc. But it is good to upgrade the python version now as the developer is on its way for debugging..Kelvin
sadly, imp is being removed in py 3.12, so I guess someone is going 'back' to importlib..Stockholm
R
2

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
Raindrop answered 31/8 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.