Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Pip module fails to build with Python 3.13 #24318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Iktomist opened this issue Aug 2, 2023 · 12 comments
Closed

Pip module fails to build with Python 3.13 #24318

Iktomist opened this issue Aug 2, 2023 · 12 comments

Comments

@Iktomist
Copy link

Iktomist commented Aug 2, 2023

Describe the issue:

Since distutils is deprecated, it's been removed in Python 3.13.

That means that trying to install Numpy via pip package gives this error:

Reproduce the code example:

me@mA13:~/Downloads$ pip3 install numpy
Defaulting to user installation because normal site-packages is not writeable
Collecting numpy
  Downloading numpy-1.25.2.tar.gz (10.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.8/10.8 MB 1.6 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done

Error message:

ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/cli/base_command.py", line 180, in exc_logging_wrapper
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/cli/req_command.py", line 248, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/commands/install.py", line 377, in run
    requirement_set = resolver.resolve(
                      ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 92, in resolve
    result = self._result = resolver.resolve(
                            ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_vendor/resolvelib/resolvers.py", line 546, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_vendor/resolvelib/resolvers.py", line 397, in resolve
    self._add_to_criteria(self.state.criteria, r, parent=None)
  File "/usr/local/lib/python3.13/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _add_to_criteria
    if not criterion.candidates:
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_vendor/resolvelib/structs.py", line 156, in __bool__
    return bool(self._sequence)
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 155, in __bool__
    return any(self)
           ^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in <genexpr>
    return (c for c in iterator if id(c) not in self._incompatible_ids)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 47, in _iter_built
    candidate = func()
                ^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 206, in _make_candidate_from_link
    self._link_candidate_cache[link] = LinkCandidate(
                                       ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 293, in __init__
    super().__init__(
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 156, in __init__
    self.dist = self._prepare()
                ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 225, in _prepare
    dist = self._prepare_distribution()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 304, in _prepare_distribution
    return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/operations/prepare.py", line 538, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/operations/prepare.py", line 653, in _prepare_linked_requirement
    dist = _get_prepared_distribution(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/operations/prepare.py", line 69, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/distributions/sdist.py", line 48, in prepare_distribution_metadata
    self._install_build_reqs(finder)
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/distributions/sdist.py", line 118, in _install_build_reqs
    build_reqs = self._get_build_requires_wheel()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/distributions/sdist.py", line 95, in _get_build_requires_wheel
    return backend.get_requires_for_build_wheel()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_internal/utils/misc.py", line 697, in get_requires_for_build_wheel
    return super().get_requires_for_build_wheel(config_settings=cs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 166, in get_requires_for_build_wheel
    return self._call_hook('get_requires_for_build_wheel', {
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 321, in _call_hook
    raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pyproject_hooks._impl.BackendUnavailable: Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend
    obj = import_module(mod_path)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1293, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1266, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1216, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 400, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1293, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1266, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1237, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 841, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1002, in exec_module
  File "<frozen importlib._bootstrap>", line 400, in _call_with_frames_removed
  File "/tmp/pip-build-env-vg8lvg3i/overlay/lib/python3.13/site-packages/setuptools/__init__.py", line 10, in <module>
    import distutils.core
ModuleNotFoundError: No module named 'distutils'

Runtime information:

(No currently running NumPy installation)

Context for the issue:

The latest version of the NumPy sources should come with detailed instructions for compiling NumPy and requirements from source.

@mattip
Copy link
Member

mattip commented Aug 2, 2023

pip install numpy with 3.13 shouldn't work. That version is clearly marked for python 3.9, 3.10, 3.11 only.

@rgommers
Copy link
Member

rgommers commented Aug 4, 2023

Indeed. If you use CPython main, please install from NumPy main too @Iktomist. There's nothing to do here, so I will close this issue.

@domdfcoding
Copy link
Contributor

Even with numpy main I can't get it to build due to meson lacking Python 3.13 support (mesonbuild/meson#12401)

@rgommers
Copy link
Member

Thanks @domdfcoding. I'll get that fixed.

@rgommers
Copy link
Member

Okay, I had a look and that'll be a while. I fixed two of the issues, and then hit:

numpy/random/bit_generator.cpython-313-x86_64-linux-gnu.so.p/numpy/random/bit_generator.pyx.c:19614:35: error: β€˜_PyObject_NextNotImplemented’ undeclared (first use in this function); did you mean β€˜PyObject_HashNotImplemented’?
19614 |         if (unlikely(iternext == &_PyObject_NextNotImplemented))

That's a private function used by Cython.

There's a reason we don't test with Python pre-releases until May or so - lots of things get randomly broken. I'll fix up a few things, but then it's up to whoever cares about this to submit patches. It's about 6 months early for us to really worry about Python 3.13.

@richard-scott
Copy link

What version was this fixed in? I get problems installing v1.26.4 on Python 3.13-dev.

numpy.txt

@mattip
Copy link
Member

mattip commented Sep 4, 2024

From the log, you are using cython 3.0.11. Does cython>=3.1 fix the problem?

@richard-scott
Copy link

I upgraded my cython version to v3.1.0a0 with this:

python3 -m pip install --upgrade git+https://github.com/cython/cython.git

And it still fails to install this:

pip3 install numpy==1.26.4

@mattip
Copy link
Member

mattip commented Sep 4, 2024

I think you need to do pip3 install --no-build-isolation numpy==1.26.4 to use your local packages.

@richard-scott
Copy link

I think you need to do pip3 install --no-build-isolation numpy==1.26.4 to use your local packages.

Nope, that totally bombs out with:

ModuleNotFoundError: No module named 'mesonpy'

I'm not after a fix; I just wanted to report that it doesn't consistently work on Python 3.13.

@mattip
Copy link
Member

mattip commented Sep 5, 2024

Right, python3.13 is not supported with 1.26.4. You need to use 2.1+. Sorry I didn't notice that previously.

@char101
Copy link

char101 commented Oct 9, 2024

I just installed python 3.13.0 and didn't have any problem installing numpy 1.26.4.

[Wed Oct 09 11:22] A:\Lang\python\3.13
> pip install "numpy<2"
Collecting numpy<2
  Using cached numpy-1.26.4.tar.gz (15.8 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: numpy
  Building wheel for numpy (pyproject.toml) ... done
  Created wheel for numpy: filename=numpy-1.26.4-cp313-cp313-win_amd64.whl size=6127548 sha256=d29a38e804f6ee825436dbae9c0b726863d1671e56a4c8b2ab453e0dd880b258
  Stored in directory: b:\cache\pip\wheels\8b\2d\9f\b6b46373f328e2ef50388915d351ccacbedac929459b5459bf
Successfully built numpy
Installing collected packages: numpy
  WARNING: The script f2py.exe is installed in 'A:\Lang\python\3.13\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed numpy-1.26.4

[Wed Oct 09 11:26] A:\Lang\python\3.13
> py
Python 3.13.0 (main, Oct  9 2024, 09:35:48) [Clang 19.1.0 ] 64 bit (AMD64) with MSC v.1939 CRT] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants