-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InstalledRepository load() breaks if there's an empty string for a env.sys_path variable #1953
Comments
I get the same error and stack trace, although I can't comment right now on what the env.sys_path looks like for me. Mac OSX 10.14.5 |
Any idea how to work around this issue? I am hit by this as well right now in a CI build but it doesn't happen on my local machine with the same poetry version being used. |
I debugged this a bit further. For me this occurs when
|
Some further reference on why this happens: https://docs.python.org/3/library/sys.html#sys.path
|
I'm experiencing the same issue when using |
I can confirm the workaround by @sisp. For me the issue came up, when I added a package dependency from a private package index and tried to run tests with tox. Running |
I did some more digging around, it looks like the package metadata from virtualenv 20.0 is missing
Should this be handled inside poetry, or should this be raised as a bug to virtualenv? |
+1 to the number of people hit by this |
Tox does not pin down the virtualenv version, so this seems broken (for everyone?) since 10 February. https://github.com/tox-dev/tox/blob/6472eac8fc4f0c222d9f40c4572aafbca72c40db/setup.cfg#L47 |
Here is a reproduction using Docker: https://gist.github.com/cjolowicz/078edda96f44ab593cc6442ac9ebaa8d Run like this: git clone https://gist.github.com/078edda96f44ab593cc6442ac9ebaa8d.git
cd 078edda96f44ab593cc6442ac9ebaa8d/
sh test.sh |
This issue is not caused by an empty string in Rather, the virtual environments created by virtualenv >= 20.0 contain marker files, which cause This has been reported to virtualenv here: pypa/virtualenv#1589 |
The fix is in virtualenv's master. On a related note, Poetry depends on a rather old version of importlib_metadata ( Python 3.8.2 (due 2020-02-17) incorporates changes from importlib_metadata 1.4 and is therefore also not affected by the bug. |
What of the different options is likely to result in the fastest fix for users? Would be nice to get this resolved quickly. So far, I have to patch all CI pipelines I am maintaining to avoid the issue. |
This is resolved with virtualenv 20.0.3, released today. @languitar Upgrade your CI to the latest virtualenv by removing the pin or pointing it to 20.0.3. |
Thank you all for reporting and keeping the community up-to-date. Good work 👍 |
I'm still seeing this whilst using nox: def deps(session):
session.install("virtualenv<20", "poetry")
session.run("poetry", "install") results in Same result for virtualenv versions 20.0.3 and 20.0.4. |
@pcp1976 Can you try deleting virtualenv's user data directory, as described here? |
Yep @cjolowicz, that's fixed it - lovely job, thanks. |
So I also having the same problem, and i dont have virtualenv installed, only pyenv + pipx + poetry
when i debug poetry I'm having a empty string as sys.path
and that first "" was breaking poetry so I made this PR to fix it #2092 |
I deleted my virtualenv user data and ran |
@uelei The empty string in sys.path is Python's way of representing the current directory. @uelei and @revmischa: Can you provide some more information about the problem you encounter (error message, traceback if possible), which environment you run in (operating system, versions of Python and relevant tools), and ideally how to reproduce the issue? The problem identified earlier is caused by marker files in the virtual environment, with the file extension Thanks for your reports! |
I'm running into the same issue as described by OP after upgrading some packages. Tried upgrading/downgrading virtualenv, removing appdata, and the other suggestions described here. Not sure how to proceed. This is on Python 3.8.2 on Windows 10 (poetry v1.0.5, virtualenv v20.0.20). poetry install -vvv
[TypeError] expected string or bytes-like object
Traceback (most recent call last):
File "C:\Users\Stef\.poetry\lib\poetry\_vendor\py3.8\clikit\console_application.py", line 131, in run
status_code = command.handle(parsed_args, io)
File "C:\Users\Stef\.poetry\lib\poetry\_vendor\py3.8\clikit\api\command\command.py", line 120, in handle
status_code = self._do_handle(args, io)
File "C:\Users\Stef\.poetry\lib\poetry\_vendor\py3.8\clikit\api\command\command.py", line 171, in _do_handle
return getattr(handler, handler_method)(args, io, self)
File "C:\Users\Stef\.poetry\lib\poetry\_vendor\py3.8\cleo\commands\command.py", line 92, in wrap_handle
return self.handle()
File "C:\Users\Stef\.poetry\lib\poetry\console\commands\install.py", line 47, in handle
installer = Installer(
File "C:\Users\Stef\.poetry\lib\poetry\installation\installer.py", line 55, in __init__
installed = self._get_installed()
File "C:\Users\Stef\.poetry\lib\poetry\installation\installer.py", line 488, in _get_installed
return InstalledRepository.load(self._env)
File "C:\Users\Stef\.poetry\lib\poetry\repositories\installed_repository.py", line 28, in load
package = Package(name, version, version)
File "C:\Users\Stef\.poetry\lib\poetry\packages\package.py", line 43, in __init__
self._name = canonicalize_name(name)
File "C:\Users\Stef\.poetry\lib\poetry\utils\helpers.py", line 26, in canonicalize_name
return _canonicalize_regex.sub("-", name).lower() |
A simple work-around is to change https://github.com/python-poetry/poetry/blob/master/poetry/repositories/installed_repository.py#L25 to: name = distribution.metadata["name"]
if not name:
continue |
To those still having problems even after upgrading virtualenv, see this comment (in short, remove any .egg-info folder from your project). |
@stefsmeets When you create a new empty virtual environment (with Virtualenv or Conda) and run I've encountered this problem when packages from other |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
-vvv
option).Issue
I ran into an error that pops up as:
expected string or bytes-like object
. I followed the stack trace and found the location where it happens:/.poetry/lib/poetry/repositories/installed_repository.py
The problem is in the load() function where it calls to get a list of paths or something using the env.sys_path variable. For me it looked like this:
'''
for distribution in sorted(
metadata.distributions(path=env.sys_path), key=lambda d: str(d._path),
):
'''
But I know that this is a little different between versions, so I'll specifically say that the issue was the env.sys_path. My env.sys_path was returning one string that's empty in it's list. I don't know why, I just know it does that. The empty string then is passed along with the rest of the code which assumes that it is a distribution package with metadata. It specifically passes along a None value which then breaks things later. The load() function needs to have logic to handle the case where env.sys_path has an empty string in the return values.
I was able to fix it by adding a simple check after the values are returned:
I tried cleaning the names for env.sys_path before they're used but then I get a different weird error:
So I just did the simple fix where I check if name is None.
Simple fix, should be quick to add to the next release.
Stack trace:
The text was updated successfully, but these errors were encountered: