`poetry install` in 3.5 env - "AttributeError: 'PosixPath' object has no attribute 'endswith'"
See original GitHub issue-
Poetry version: 1.2.2
-
Python version: System python : 3.10.8, env version: 3.5.10
-
OS version and name: Linux (Manjaro)
-
pyproject.toml: https://github.com/alorence/django-modern-rpc/blob/better-dependencies-management/pyproject.toml
-
[ x ] I am on the latest stable Poetry version, installed using a recommended method.
-
[ x ] I have searched the issues of this repo and believe that this is not a duplicate.
-
[ x ] I have consulted the FAQ and blog for any relevant entries or release notes.
-
[ x ] If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption) and have included the output below.
Issue
I am managing a FOSS project with Python 3.5 and 3.6 support. I know that Poetry runs only on Python 3.7+, but I assume I can use it with my python system (3.10) while working in an environment:
β― python -V
Python 3.10.8
β― pyenv local
system
3.11
3.5
β― poetry env use 3.5
Creating virtualenv django-modern-rpc-4Wp8Q-da-py3.5 in /home/alorence/.cache/pypoetry/virtualenvs
Using virtualenv: /home/alorence/.cache/pypoetry/virtualenvs/django-modern-rpc-4Wp8Q-da-py3.5
β― poetry run python -V
Python 3.5.10
Now, I try to install the dependencies inside the 3.5 environment:
β― poetry install -vvv
Loading configuration file /home/alorence/.config/pypoetry/config.toml
Using virtualenv: /home/alorence/.cache/pypoetry/virtualenvs/django-modern-rpc-4Wp8Q-da-py3.5
Project environment contains an empty path in sys_path, ignoring.
Installing dependencies from lock file
Finding the necessary packages for the current system
Package operations: 33 installs, 0 updates, 0 removals, 1 skipped
β’ Installing zipp (1.2.0): Pending...
[keyring.backend] Loading KWallet
[keyring.backend] Loading SecretService
[keyring.backend] Loading Windows
[keyring.backend] Loading chainer
[keyring.backend] Loading libsecret
[keyring.backend] Loading macOS
Creating new session for pypi.org
[urllib3.connectionpool] Starting new HTTPS connection (1): pypi.org:443
[urllib3.connectionpool] https://pypi.org:443 "GET /pypi/zipp/1.2.0/json HTTP/1.1" 304 0
β’ Installing zipp (1.2.0): Failed
Stack trace:
1 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/utils/env.py:1459 in _run
1457β
1458β if input_:
β 1459β output = subprocess.run(
1460β command,
1461β stdout=subprocess.PIPE,
CalledProcessError
Command '['/home/alorence/.cache/pypoetry/virtualenvs/django-modern-rpc-4Wp8Q-da-py3.5/bin/python', '-W', 'ignore', '-']' returned non-zero exit status 1.
at /usr/lib/python3.10/subprocess.py:526 in run
522β # We don't call process.wait() as .__exit__ does that for us.
523β raise
524β retcode = process.poll()
525β if check and retcode:
β 526β raise CalledProcessError(retcode, process.args,
527β output=stdout, stderr=stderr)
528β return CompletedProcess(process.args, retcode, stdout, stderr)
529β
530β
The following error occurred when trying to handle this error:
Stack trace:
12 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/installation/executor.py:261 in _execute_operation
259β
260β try:
β 261β result = self._do_execute_operation(operation)
262β except EnvCommandError as e:
263β if e.e.returncode == -2:
11 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/installation/executor.py:334 in _do_execute_operation
332β return 0
333β
β 334β result: int = getattr(self, f"_execute_{method}")(operation)
335β
336β if result != 0:
10 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/installation/executor.py:454 in _execute_install
452β
453β def _execute_install(self, operation: Install | Update) -> int:
β 454β status_code = self._install(operation)
455β
456β self._save_url_reference(operation)
9 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/installation/executor.py:488 in _install
486β archive = self._download_link(operation, Link(package.source_url))
487β else:
β 488β archive = self._download(operation)
489β
490β operation_message = self.get_operation_message(operation)
8 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/installation/executor.py:633 in _download
631β
632β def _download(self, operation: Install | Update) -> Path:
β 633β link = self._chooser.choose_for(operation.package)
634β
635β if link.yanked:
7 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/installation/chooser.py:88 in choose_for
86β continue
87β
β 88β if not Wheel(link.filename).is_supported_by_environment(self._env):
89β logger.debug(
90β "Skipping wheel %s as this is not supported by the current"
6 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/installation/chooser.py:56 in is_supported_by_environment
54β
55β def is_supported_by_environment(self, env: Env) -> bool:
β 56β return bool(set(env.supported_tags).intersection(self.tags))
57β
58β
5 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/utils/env.py:1370 in supported_tags
1368β def supported_tags(self) -> list[Tag]:
1369β if self._supported_tags is None:
β 1370β self._supported_tags = self.get_supported_tags()
1371β
1372β return self._supported_tags
4 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/utils/env.py:1674 in get_supported_tags
1672β
1673β def get_supported_tags(self) -> list[Tag]:
β 1674β output = self.run_python_script(GET_SYS_TAGS)
1675β assert isinstance(output, str)
1676β
3 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/utils/env.py:1438 in run_python_script
1436β
1437β def run_python_script(self, content: str, **kwargs: Any) -> int | str:
β 1438β return self.run(self._executable, "-W", "ignore", "-", input_=content, **kwargs)
1439β
1440β def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
2 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/utils/env.py:1430 in run
1428β def run(self, bin: str, *args: str, **kwargs: Any) -> str | int:
1429β cmd = self.get_command_from_bin(bin) + list(args)
β 1430β return self._run(cmd, **kwargs)
1431β
1432β def run_pip(self, *args: str, **kwargs: Any) -> int | str:
1 ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/utils/env.py:1712 in _run
1710β def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
1711β kwargs["env"] = self.get_temp_environ(environ=kwargs.get("env"))
β 1712β return super()._run(cmd, **kwargs)
1713β
1714β def get_temp_environ(
EnvCommandError
Command ['/home/alorence/.cache/pypoetry/virtualenvs/django-modern-rpc-4Wp8Q-da-py3.5/bin/python', '-W', 'ignore', '-'] errored with the following return code 1, and output:
Traceback (most recent call last):
File "<stdin>", line 9, in <module>
File "<frozen importlib._bootstrap_external>", line 581, in spec_from_file_location
AttributeError: 'PosixPath' object has no attribute 'endswith'
input was :
import importlib.util
import json
import sys
from pathlib import Path
spec = importlib.util.spec_from_file_location(
"packaging", Path(r"/home/alorence/.local/pipx/venvs/poetry/lib/python3.10/site-packages/packaging/__init__.py")
)
packaging = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = packaging
spec = importlib.util.spec_from_file_location(
"packaging.tags", Path(r"/home/alorence/.local/pipx/venvs/poetry/lib/python3.10/site-packages/packaging/tags.py")
)
packaging_tags = importlib.util.module_from_spec(spec)
spec.loader.exec_module(packaging_tags)
print(
json.dumps([(t.interpreter, t.abi, t.platform) for t in packaging_tags.sys_tags()])
)
at ~/.local/pipx/venvs/poetry/lib/python3.10/site-packages/poetry/utils/env.py:1476 in _run
1472β output = subprocess.check_output(
1473β command, stderr=subprocess.STDOUT, env=env, **kwargs
1474β )
1475β except CalledProcessError as e:
β 1476β raise EnvCommandError(e, input=input_)
1477β
1478β return decode(output)
1479β
1480β def execute(self, bin: str, *args: str, **kwargs: Any) -> int:
I think the relevant part is
AttributeError: βPosixPathβ object has no attribute βendswithβ
Giving a Path instance to importlib.util.spec_from_file_location may be problematic in Python 3.5 environment, as explained in the documentation:
New in version 3.4.
Changed in version 3.6: Accepts a path-like object.
Issue Analytics
- State:
- Created 10 months ago
- Comments:6 (3 by maintainers)

Top Related StackOverflow Question
I understand. Maybe this issue should remain open at least until a decision is made to either
The official poetry 1.2 announce on the blog mentionned only the end of python 2.7 projects support : https://python-poetry.org/blog/announcing-poetry-1.2.0/#dropping-support-for-managing-python-27-projects
presumably that message comes from the 1.1 codebase, so thereβs no need to worry about updating that.
Neither dropping support for 3.5 projects nor committing to that support is a decision that I can take - Iβd wait for someone to show up who does have such authority before submitting any MRs.
(of course if you have any ideas about how to achieve what that code is trying to achieve without being stuck at old versions of packaging, that would be greatβ¦)