poetry: Python 3.8 - "TypeError: expected string or bytes-like object" with poetry install
-
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). -
OS version and name: gitlab python3.8 docker image
-
Poetry version: 1.0.3
-
Link of a Gist with the contents of your pyproject.toml file: gitlab-ci report
Issue
I have a project using poetry that use Gitlab-CI and tox to run tests in several environments. The very same code works in python 3.5, 3.6 and 3.7, but produce the following error with python 3.8. The error message is not very clear so I am not sure what is going on.
You can view all the successful executions here and the failing one here. If it matters, you can see the tox configuration here and the poetry configuration here.
py38 run-test: commands[0] | poetry install -vvv --extras all
Using virtualenv: /builds/yaal/sheraf/.tox/py38
[TypeError]
expected string or bytes-like object
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/clikit/console_application.py", line 131, in run
status_code = command.handle(parsed_args, io)
File "/usr/local/lib/python3.8/site-packages/clikit/api/command/command.py", line 120, in handle
status_code = self._do_handle(args, io)
File "/usr/local/lib/python3.8/site-packages/clikit/api/command/command.py", line 171, in _do_handle
return getattr(handler, handler_method)(args, io, self)
File "/usr/local/lib/python3.8/site-packages/cleo/commands/command.py", line 92, in wrap_handle
return self.handle()
File "/usr/local/lib/python3.8/site-packages/poetry/console/commands/install.py", line 47, in handle
installer = Installer(
File "/usr/local/lib/python3.8/site-packages/poetry/installation/installer.py", line 55, in __init__
installed = self._get_installed()
File "/usr/local/lib/python3.8/site-packages/poetry/installation/installer.py", line 488, in _get_installed
return InstalledRepository.load(self._env)
File "/usr/local/lib/python3.8/site-packages/poetry/repositories/installed_repository.py", line 26, in load
package = Package(name, version, version)
File "/usr/local/lib/python3.8/site-packages/poetry/packages/package.py", line 42, in __init__
self._name = canonicalize_name(name)
File "/usr/local/lib/python3.8/site-packages/poetry/utils/helpers.py", line 26, in canonicalize_name
return _canonicalize_regex.sub("-", name).lower()
ERROR: InvocationError for command /usr/local/bin/poetry install -vvv --extras all (exited with code 1)
Thank you for your help
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 20
- Comments: 34 (7 by maintainers)
This will also happen if you somehow end up with an .egg-info file (presumably malformatted) in your project directory. I think I created one unintentionally while experimenting with dephell, but regardless of the source this is what you can expect to see:
What is the solution to this? This ticket is closed, but I am still getting the issue. I have read every comment here and did not see what allowed this to be closed. If this is fixed in some version of poetry, can someone please be explicit about which specific version of poetry this is fixed in? Thank you.
For me it was also due to activated conda environment. So it was fixed by
conda deactivate
This issue still exists in the latest 1.1.7
I solved this problem by deleting the virtual environment. First you can get ENV_NAME by typing
poetry env list
, and then typingpoetry env remove ENV_NAME
to delete this virtual environment.Seeing the exact same issue, but on Python 3.7.2 and poetry 1.0.3. Downgrading to poetry 1.0.2 made no difference.
I met this bug again in poetry==1.1.0 on windows.
Hi, I experience the same issue, and eventually traced it to this:
e.g. at this point env.sys_path contains an empty string as the first item, which somehow eventually leads to ‘name’ passed to canonicalize_name being None skipping the empty entry as i did here seems to fix it for now
@repnop It would be more helpful for you if you communicated meaningful information, such as the
pyproject.toml
, the name of the git dependency that causes the issue, the full console output showing the error message.Hitting this on a fresh project, with 1.1.4 latest release installed via pip
edit: I commented out a git dep and now it let me
poetry install
, not sure if that’s related or useful info@abn OK, I’ll create a repo with github actions to reproduce it.
In my case, I moved pyproject.toml to the root directory of the git repository and that fixed the problem. But the error occurred if pyproject.toml was placed in the sub directory.
OK
git repository root/ ├ pyproject.toml ├ src/
NG
git repository root/ ├ src/ └ pyproject.toml
(repository = GitHub repository of poetry package)
My idea is that this error will occur allways if the name of installed package is missing for poetry.
I want install some package shared between my projects on the development machine (something like -e mode of pip). I create empty mypackage/ and inside mypackage/mypackage/ with code.
Now: Both
poetry add mypackage/
andpoetry add mypackage/mypackage/
will fail with the error above.Then I create
mypackage/setup.py
withsetup(name='mypackage', .....). And now:
poetry add mypackage/` will install the editable package without problems.Minimum
setup.py
content for this goal is:Maybe this will help to identify the reasons more exactly?
Same here. I can’t get to workaround this with a git dependency.
@sinoroc its an internal work project so the git dependency is not public, but its a simple
the full error is exactly the same as above, and I did hit it when trying to install
aiomysql
orsanic
before that (but it hasn’t happened with them since I fixed? whatever the problem was there). I tried deleting the venv multiple times and reinstalling the dependencies.