pendulum
pendulum copied to clipboard
Installation fails: `ModuleNotFoundError: No module named 'setuptools'`
- [x] I have searched the issues of this repo and believe that this is not a duplicate.
- [x] I have searched the documentation and believe that my question is not covered.
Issue
I am trying to install another package, but it features pendulum as one of its dependencies. Installation fails with the following error:
Error
$ poetry add pendulum
Using version ^2.1.2 for pendulum
Updating dependencies
Resolving dependencies... (0.3s)
Package operations: 1 install, 0 updates, 0 removals
• Installing pendulum (2.1.2): Failed
EnvCommandError
Command ['/home/user/PycharmProjects/feecc-workbench-daemon/.venv/bin/pip', 'install', '--no-deps', 'file:///home/user/.cache/pypoetry/artifacts/a1/1f/50/7e13db80973ed5410bca55389738ac39388e71ba405feced83caae75ba/pendulum-2.1.2.tar.gz'] errored with the following return code 2, and output:
Processing /home/user/.cache/pypoetry/artifacts/a1/1f/50/7e13db80973ed5410bca55389738ac39388e71ba405feced83caae75ba/pendulum-2.1.2.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 'done'
ERROR: Exception:
Traceback (most recent call last):
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 167, in exc_logging_wrapper
status = run_func(*args)
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
return func(self, options, args)
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 339, in run
requirement_set = resolver.resolve(
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 75, in resolve
collected = self.factory.collect_root_requirements(root_reqs)
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 506, in collect_root_requirements
req = self._make_requirement_from_install_req(
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 468, in _make_requirement_from_install_req
cand = self._make_candidate_from_link(
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 215, in _make_candidate_from_link
self._link_candidate_cache[link] = LinkCandidate(
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 288, in __init__
super().__init__(
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 158, in __init__
self.dist = self._prepare()
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 227, in _prepare
dist = self._prepare_distribution()
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 299, in _prepare_distribution
return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 487, in prepare_linked_requirement
return self._prepare_linked_requirement(req, parallel_builds)
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 556, in _prepare_linked_requirement
dist = _get_prepared_distribution(
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 58, in _get_prepared_distribution
abstract_dist.prepare_distribution_metadata(finder, build_isolation)
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/distributions/sdist.py", line 45, in prepare_distribution_metadata
self._install_build_reqs(finder)
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/distributions/sdist.py", line 104, in _install_build_reqs
build_reqs = self._get_build_requires_wheel()
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_internal/distributions/sdist.py", line 81, in _get_build_requires_wheel
return backend.get_requires_for_build_wheel()
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/wrappers.py", line 172, in get_requires_for_build_wheel
return self._call_hook('get_requires_for_build_wheel', {
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/wrappers.py", line 332, in _call_hook
raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pep517.wrappers.BackendUnavailable: Traceback (most recent call last):
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 89, in _build_backend
obj = import_module(mod_path)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/tmp/pip-build-env-dwhh2ky7/overlay/lib/python3.10/site-packages/poetry/core/masonry/api.py", line 14, in <module>
from poetry.core.masonry.builders.wheel import WheelBuilder
File "/tmp/pip-build-env-dwhh2ky7/overlay/lib/python3.10/site-packages/poetry/core/masonry/builders/wheel.py", line 21, in <module>
from packaging.tags import sys_tags
File "/tmp/pip-build-env-dwhh2ky7/overlay/lib/python3.10/site-packages/poetry/core/_vendor/packaging/tags.py", line 7, in <module>
import distutils.util
File "/home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/_distutils_hack/__init__.py", line 92, in create_module
return importlib.import_module('setuptools._distutils')
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'setuptools'
at /usr/lib/python3.10/site-packages/poetry/utils/env.py:1195 in _run
1191│ output = subprocess.check_output(
1192│ cmd, stderr=subprocess.STDOUT, **kwargs
1193│ )
1194│ except CalledProcessError as e:
→ 1195│ raise EnvCommandError(e, input=input_)
1196│
1197│ return decode(output)
1198│
1199│ def execute(self, bin, *args, **kwargs):
Failed to add packages, reverting the pyproject.toml file to its original content.
Setup also fails when I do it using pip instead of Poetry.
I have searched thoroughly, I tried installing setuptools and wheel both inside venv, globally and as root, upgrading pip and poetry. Nothing worked for me.
My setup:
$ python -V
Python 3.10.4
$ pip -V
pip 22.0.4 from /home/user/PycharmProjects/feecc-workbench-daemon/.venv/lib/python3.10/site-packages/pip (python 3.10)
$ poetry -V
Poetry version 1.1.13
$ uname -a
Linux endeavour 5.17.5-arch1-1 #1 SMP PREEMPT Wed, 27 Apr 2022 20:56:11 +0000 x86_64 GNU/Linux
Any help appreciated. Thank you.
I just ran into this as well, also on an Arch Linux based distro. Python 3.10.5 and pip 22.1.2. I was able to fix this by doing poetry run pip install setuptools==62.4.0
and then poetry install
.
I can't seem to figure out how to fix the environment in general so that I don't have to manually do this for every poetry
env separately.
The only fix for this bug right now is to use poetry 1.2.0b3
built from git source or at least poetry v1.2 see https://github.com/python-poetry/poetry/issues/4983
Could any maintainers of pendulum explain why was a poetry preview version required now to install pendulum as a dependancy ?
This looks like a known issue per https://github.com/pypa/pip/issues/6264#issuecomment-685230919, which is not python-poetry specific, but triggered by pip when
a PEP 517 build of a package is performed, its build requirements are installed into a directory that is added to sys.path for the subprocess that runs the build backend, but they are put later in sys.path than an older version of setuptools.
It seems from that bug that upgrading your interpreter's setuptools
install would resolve this issue.
In a brief test, I didn't see this issue with an up-to-date setuptools install.
Installation of `pendulum==2.1.2` into a venv
> py -3.10 -V
Python 3.10.2
> py -3.10 -m pip list
Package Version
----------- -------
argcomplete 2.0.0
click 8.0.4
colorama 0.4.4
packaging 21.3
pip 22.1.2
pipx 1.0.0
pyparsing 3.0.7
setuptools 62.3.2
userpath 1.8.0
wheel 0.37.1
> py -3.10 -m venv penduvenv
> .\penduvenv\Scripts\activate
> python -m pip list
Package Version
---------- -------
pip 21.2.4
setuptools 58.1.0
WARNING: You are using pip version 21.2.4; however, version 22.1.2 is available.
You should consider upgrading via the 'C:\Users\paulh\penduvenv\Scripts\python.exe -m pip install --upgrade pip' command.
> python -m pip install "pendulum==2.1.2" --no-binary pendulum
Collecting pendulum==2.1.2
Using cached pendulum-2.1.2.tar.gz (81 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Collecting pytzdata>=2020.1
Downloading pytzdata-2020.1-py2.py3-none-any.whl (489 kB)
|████████████████████████████████| 489 kB 364 kB/s
Collecting python-dateutil<3.0,>=2.6
Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting six>=1.5
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Building wheels for collected packages: pendulum
Building wheel for pendulum (PEP 517) ... done
Created wheel for pendulum: filename=pendulum-2.1.2-cp310-cp310-win_amd64.whl size=129782 sha256=b891f18d2f65935a507e96aed55b5eb43b9ecc930dd6de59a4293b79753b5863
Stored in directory: c:\users\paulh\appdata\local\pip\cache\wheels\2e\41\ed\f113e4c9dc10f6c846d69f412e9cd9aa429960a3e2e485a4f9
Successfully built pendulum
Installing collected packages: six, pytzdata, python-dateutil, pendulum
Successfully installed pendulum-2.1.2 python-dateutil-2.8.2 pytzdata-2020.1 six-1.16.0
WARNING: You are using pip version 21.2.4; however, version 22.1.2 is available.
You should consider upgrading via the 'C:\Users\paulh\penduvenv\Scripts\python.exe -m pip install --upgrade pip' command.
It's also possible that adding setuptools>=50
to the build-system.requires
array in pyproject.toml would work around the problem in this repo, or even making that a dependency of poetry-core
would work around it generally, but I don't know that this will actually work, as it might still pick up the old system-wide setuptools
install by preference and have the same issue.
You might also find that setting the env-var SETUPTOOLS_USE_DISTUTILS
to stdlib
works around the problem, but that's not really a generally-useful solution.
Can not reproduce this with any supported python version, all install pendulum
via pip
without any problem. Could anyone affected provide steps to reproduce?
Repro case for my diagnosis above, with fresh python 3.8.0. (I intended to grab 3.8 latest, but was inattentive...)
Specifically, I have not run the following, which is usually the first thing I do with a new Python setup:
# Running this would probably have fixed this.
py -3.8 -m pip install --upgrade pip setuptools wheel
> py -3.8 -m pip list
Package Version
---------- -------
pip 19.2.3
setuptools 41.2.0
WARNING: You are using pip version 19.2.3, however version 22.2.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
> py -3.8 -m venv pendvenv
> which python
C:\Users\paulh\pendvenv\Scripts\python.exe
> .\pendvenv\Scripts\activate
> python -m pip list
Package Version
---------- -------
pip 19.2.3
setuptools 41.2.0
WARNING: You are using pip version 19.2.3, however version 22.2.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
> python -m pip install "pendulum==2.1.2" --no-binary pendulum
Collecting pendulum==2.1.2
Downloading https://files.pythonhosted.org/packages/db/15/6e89ae7cde7907118769ed3d2481566d05b5fd362724025198bb95faf599/pendulum-2.1.2.tar.gz (81kB)
|████████████████████████████████| 81kB 5.1MB/s
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: pytzdata>=2020.1 in c:\users\paulh\pendvenv\lib\site-packages (from pendulum==2.1.2) (2020.1)
Requirement already satisfied: python-dateutil<3.0,>=2.6 in c:\users\paulh\pendvenv\lib\site-packages (from pendulum==2.1.2) (2.8.2)
Requirement already satisfied: six>=1.5 in c:\users\paulh\pendvenv\lib\site-packages (from python-dateutil<3.0,>=2.6->pendulum==2.1.2) (1.16.0)
Skipping bdist_wheel for pendulum, due to binaries being disabled for it.
Installing collected packages: pendulum
Running setup.py install for pendulum ... error
ERROR: Command errored out with exit status 1:
command: 'C:\Users\paulh\pendvenv\Scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\paulh\\AppData\\Local\\Temp\\pip-install-mdamxxr8\\pendulum\\setup.py'"'"'; __file__='"'"'C:\\Users\\paulh\\AppData\\Local\\Temp\\pip-install-mdamxxr8\\pendulum\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\paulh\AppData\Local\Temp\pip-record-k5rp6mo7\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\paulh\pendvenv\include\site\python3.8\pendulum'
cwd: C:\Users\paulh\AppData\Local\Temp\pip-install-mdamxxr8\pendulum\
Complete output (3 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'setuptools'
----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\paulh\pendvenv\Scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\paulh\\AppData\\Local\\Temp\\pip-install-mdamxxr8\\pendulum\\setup.py'"'"'; __file__='"'"'C:\\Users\\paulh\\AppData\\Local\\Temp\\pip-install-mdamxxr8\\pendulum\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\paulh\AppData\Local\Temp\pip-record-k5rp6mo7\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\paulh\pendvenv\include\site\python3.8\pendulum' Check the logs for full command output.
WARNING: You are using pip version 19.2.3, however version 22.2.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
A quick check in Git suggests this still affects latest 3.7, but per https://github.com/python/cpython/issues/88096 has been fixed in latest 3.8 and 3.9 (by upgrading setuptools), and per https://github.com/python/cpython/issues/87243 should have been fixed in 3.10 alpha series. The original poster shows pip 22.0.4 (which suggests setuptools would also have been new-enough), so possibly there was another issue that leads to the same failure, and my diagnosis was wrong.
On the other hand, I just noticed that the original poster was on Arch Linux, and the pip 22.0.4 was running from a venv (while Poetry was installed in /usr/lib...) so perhaps the setuptools (and pip) in /usr/lib is too old, because it's being managed by the Linux vendor, and did not keep up with the ensurepip
updates I linked to above.
Edit: Confirmed that Arch Linux disables ensurepip, and never had a python-pip 22.0.4 package, so the version in the venv is (presumably) newer than what was on the system. However, it doesn't appear that Arch's python-pip package specifies a versioned dependency on setuptools, so it's definitely possible that an old python-setuptools
package had been left installed in the system-wide install.
So I'd say my diagnosis is feasible, but to prove it, we'd need the list of python packages installed on that system and expect to see a python-setuptools
package older than 50.0.0. (Or maybe there's other paths to hit this than system-wide setuptools older than 50.0.0; the pip issue I linked to has a bunch of different repros and symptoms with newer setuptools, and "the Python packaging on Debian" showed up a couple of times as well).
This is a poetry bug https://github.com/python-poetry/poetry/issues/4242 Basically, poetry 1.2 adds setuptools to poetry.lock. Then poetry 1.1 sees setuptools in the lock file, freaks out and removes it from the virtual environment.