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.

"expected string or bytes-like object" on poetry install

See original GitHub issue
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

When I run poetry install in a private GitHub runner on an GHES installation I started getting an error (see further below for full output):

  TypeError

  expected string or bytes-like object

  at /usr/local/lib/python3.8/site-packages/poetry/core/utils/helpers.py:24 in canonicalize_name

Debug output

Creating virtualenv amp-portal in /__w/backend/backend/amp-portal/.venv
Using virtualenv: /__w/backend/backend/amp-portal/.venv

  Stack trace:

  11  /usr/local/lib/python3.8/site-packages/clikit/console_application.py:131 in run
       129β”‚             parsed_args = resolved_command.args
       130β”‚ 
     β†’ 131β”‚             status_code = command.handle(parsed_args, io)
       132β”‚         except KeyboardInterrupt:
       133β”‚             status_code = 1

  10  /usr/local/lib/python3.8/site-packages/clikit/api/command/command.py:120 in handle
       118β”‚     def handle(self, args, io):  # type: (Args, IO) -> int
       119β”‚         try:
     β†’ 120β”‚             status_code = self._do_handle(args, io)
       121β”‚         except KeyboardInterrupt:
       122β”‚             if io.is_debug():

   9  /usr/local/lib/python3.8/site-packages/clikit/api/command/command.py:163 in _do_handle
       161β”‚         if self._dispatcher and self._dispatcher.has_listeners(PRE_HANDLE):
       162β”‚             event = PreHandleEvent(args, io, self)
     β†’ 163β”‚             self._dispatcher.dispatch(PRE_HANDLE, event)
       164β”‚ 
       165β”‚             if event.is_handled():

   8  /usr/local/lib/python3.8/site-packages/clikit/api/event/event_dispatcher.py:22 in dispatch
        20β”‚ 
        21β”‚         if listeners:
     β†’  22β”‚             self._do_dispatch(listeners, event_name, event)
        23β”‚ 
        24β”‚         return event

   7  /usr/local/lib/python3.8/site-packages/clikit/api/event/event_dispatcher.py:89 in _do_dispatch
        87β”‚                 break
        88β”‚ 
     β†’  89β”‚             listener(event, event_name, self)
        90β”‚ 
        91β”‚     def _sort_listeners(self, event_name):  # type: (str) -> None

   6  /usr/local/lib/python3.8/site-packages/poetry/console/config/application_config.py:141 in set_installer
       139β”‚ 
       140β”‚         poetry = command.poetry
     β†’ 141β”‚         installer = Installer(
       142β”‚             event.io,
       143β”‚             command.env,

   5  /usr/local/lib/python3.8/site-packages/poetry/installation/installer.py:65 in __init__
        63β”‚         self._installer = self._get_installer()
        64β”‚         if installed is None:
     β†’  65β”‚             installed = self._get_installed()
        66β”‚ 
        67β”‚         self._installed_repository = installed

   4  /usr/local/lib/python3.8/site-packages/poetry/installation/installer.py:561 in _get_installed
       559β”‚ 
       560β”‚     def _get_installed(self):  # type: () -> InstalledRepository
     β†’ 561β”‚         return InstalledRepository.load(self._env)
       562β”‚ 

   3  /usr/local/lib/python3.8/site-packages/poetry/repositories/installed_repository.py:118 in load
       116β”‚                 path = Path(str(distribution._path))
       117β”‚                 version = distribution.metadata["version"]
     β†’ 118β”‚                 package = Package(name, version, version)
       119β”‚                 package.description = distribution.metadata.get("summary", "")
       120β”‚ 

   2  /usr/local/lib/python3.8/site-packages/poetry/core/packages/package.py:51 in __init__
        49β”‚         Creates a new in memory package.
        50β”‚         """
     β†’  51β”‚         super(Package, self).__init__(
        52β”‚             name,
        53β”‚             source_type=source_type,

   1  /usr/local/lib/python3.8/site-packages/poetry/core/packages/specification.py:19 in __init__
        17β”‚     ):  # type: (str, Optional[str], Optional[str], Optional[str], Optional[str], Optional[List[str]]) -> None
        18β”‚         self._pretty_name = name
     β†’  19β”‚         self._name = canonicalize_name(name)
        20β”‚         self._source_type = source_type
        21β”‚         self._source_url = source_url

  TypeError

  expected string or bytes-like object

  at /usr/local/lib/python3.8/site-packages/poetry/core/utils/helpers.py:24 in canonicalize_name
       20β”‚ _canonicalize_regex = re.compile("[-_]+")
       21β”‚ 
       22β”‚ 
       23β”‚ def canonicalize_name(name):  # type: (str) -> str
    β†’  24β”‚     return _canonicalize_regex.sub("-", name).lower()
       25β”‚ 
       26β”‚ 
       27β”‚ def module_name(name):  # type: (str) -> str
       28β”‚     return canonicalize_name(name).replace(".", "_").replace("-", "_")

Dockerfile for base docker image

ARG DEBIAN_VERSION=buster
ARG PYTHON_VERSION=3.8
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION}

ENV \
    DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    POETRY_VIRTUALENVS_IN_PROJECT=true \
    POETRY_NO_INTERACTION=1

RUN set -x \
    && apt-get update \
    && apt-get install -yq --no-install-recommends libpq-dev build-essential sudo \
    && rm -rf /var/lib/apt/lists/*

RUN pip install poetry==1.1.4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:27
  • Comments:61 (5 by maintainers)

github_iconTop GitHub Comments

15reactions
dbalabkacommented, May 7, 2021

In my case poetry fails with a similar error when I’m trying to add a package:

poetry add "git+https://github.com/streamlit/streamlit.git#0.81.2.dev20210506"
12reactions
debonzi-gerucommented, Jun 8, 2021

I am not sure if it has anything to do with what you guys are experiencing but after get this problem localy in serveral projects and find this issue I started to debug poetry and found out that the issue was happening because, for some reason, I had a .egg-info directory. I could than see that poetry was checking on it for installed packages and there was a distribution object with no name in its metadata.

https://github.com/python-poetry/poetry/blob/977a72ca4614b6bb6e5ac885ec666e18c03c0a1d/poetry/repositories/installed_repository.py#L233

Reproducing the error: (I dont know how it would behave with a valid .egg-info directory)

# Working as expected
~/open-offertator$ poetry install
Installing dependencies from lock file

No dependencies to install or update

Installing the current project: open_offertator (0.1.0)

# Create a .egg-info directory
~/open-offertator$ mkdir open_offertator.egg-info/

# Try poetry again
~/open-offertator$ poetry install

  TypeError

  expected string or bytes-like object

  at ~/.pyenv/versions/3.9.4/lib/python3.9/site-packages/poetry/core/utils/helpers.py:27 in canonicalize_name
       23β”‚ _canonicalize_regex = re.compile(r"[-_]+")
       24β”‚ 
       25β”‚ 
       26β”‚ def canonicalize_name(name):  # type: (str) -> str
    β†’  27β”‚     return _canonicalize_regex.sub("-", name).lower()
       28β”‚ 
       29β”‚ 
       30β”‚ def module_name(name):  # type: (str) -> str
       31β”‚     return canonicalize_name(name).replace(".", "_").replace("-", "_")

I hope it helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Notebooks/script don't recognize project package using poetry
If I run poetry install and try to import anything from source, whether it's from the ... TypeError expected string or bytes-like object...
Read more >
TypeError: expected string or bytes-like object in Python
The Python TypeError: expected string or bytes-like object occurs when we pass an argument of a different type to a method that expects...
Read more >
How to Fix: Typeerror: expected string or bytes-like object
This error typically occurs when you attempt to use the re.sub() function to replace certain patterns in an object but the object you're...
Read more >
got a expected string or bytes-like object when running install
[X] I am on the latest Poetry version. [X] I have searched the issues of this repo and believe that this is not...
Read more >
TypeError expected string or bytes-like object - STechies
You might have used various functions in Python. While working with functions, there may be an error called β€œTypeError expected string or bytes-like...
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