question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`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 (-vvv option) 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’

coming from https://github.com/python-poetry/poetry/blob/d02c71cf0262b4741852a9ca0333db1021ac4b9f/src/poetry/utils/env.py#L71-L73

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:open
  • Created 10 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alorencecommented, Nov 30, 2022

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.

I understand. Maybe this issue should remain open at least until a decision is made to either

  • officially drop the support of managing python 3.5 projects or
  • find a way to repair this feature

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

0reactions
dimblebycommented, Nov 30, 2022

in the next feature release of Poetry (1.2)

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…)

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'PosixPath' object has no attribute 'startswith ...
I am using Python 3.5. Django 2.1. BASE_DIR = Path(__file__).resolve().parent.parent.parent STATIC_ROOT = BASE_DIR / 'static'.
Read more >
'PosixPath' object has no attribute 'endswith' : PY-48506
error on pydev_monkey in debug mode AttributeError: 'PosixPath' object has no attribute 'endswith'. 2. Is duplicated by 1 Also fixes 1.
Read more >
Dependency Management With Python Poetry
Start a new Poetry project; Add Poetry to an existing project; Use the pyproject.toml file; Pin dependencies; Install dependencies with poetry.
Read more >
Xonsh Change Log - xonsh 0.13.2 documentation
Fixed issue where xontribs were failing from AttributeError: '_MergedKeyBindings' object has no attribute 'add'. Authors: Anthony Scopatz. David Strobach.
Read more >
FS#67624 : [python-jedi] Doesn't work with Python 3.8.5 due ...
_path is not None and self._path.endswith('.pyi'): AttributeError: 'PosixPath' object has no attribute 'endswith' Steps to reproduce:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found