python-poetry / python-poetry/poetry
poetry commands suddenly stopped working (probably because of global python update)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 34.3k
- Forks
- 2.5k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 30
Description
Description
Hi! I have a global python 3.13 installation that I installed through a software installation and updates tool provided by the IT department of my workplace. The virtual environments I have created using Poetry were based on that python installation. Navigating to one of my python projects (either in cmd or powershell, I've tested both), I could until very recently run any Poetry command without error. Today, any command except poetry about fails with
Command ['C:\\Users\\<my_user>\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\<my-project-name>-<some-poetry-generated-string>-py3.13\\Scripts\\python.exe', '-I', '-W', 'ignore', '-c', 'import sys\n\nif hasattr(sys, "real_prefix"):\n print(sys.real_prefix)\nelif hasattr(sys, "base_prefix"):\n print(sys.base_prefix)\nelse:\n print(sys.prefix)\n'] errored with the following return code 1
Error output:
Traceback (most recent call last):
File "C:\Program Files\Python313\Lib\linecache.py", line 228, in _register_code
for const in code.co_consts:
^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'co_consts'
I think what changed since yesterday is that there was an automatic update of my global python installation from 3.13.2 to 3.13.3. This seems in line with the selected interpreter name shown in my editor (VS Code) in the bottom right corner, which shows
3.13.2 ('<my-project-name>-<some-poetry-generated-string>-py3.13')
and the output I get from running python in a terminal:
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
Poetry documentation states that
[...] you can use the env use command to tell Poetry which Python version to use for the current project.
so I tried to use that command to reset the base python path, but also that command fails with the above error. Trying to use poetry to delete the virtual environment also failed with the same error.
I sorted it out by simply navigating to the poetry virtualenvs folder and deleting the whole virtual environment folder (without using Poetry -- I just used the file explorer), and then I could use poetry install to (re)create the environment.
If Poetry is designed to handle such changes to a base installation, I believe this is indeed a bug report. In any case I think a more explanatory error message would be helpful for anyone else running into this, so if this shouldn't be a bug report, maybe it could be a feature request.
PS: I used Poetry 2.1.1 when I encountered the issue. Since then I've tried updating to 2.1.2, but the issue is still present.
Workarounds
Not letting anyone make changes to your python base installation(s) would prevent the issue.
Poetry Installation Method
Windows Powershell: (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
Operating System
Windows 10
Poetry Version
Poetry (version 2.1.2)
Poetry Configuration
cache-dir = "C:\\Users\\<my-user>\\AppData\\Local\\pypoetry\\Cache"
data-dir = "C:\\Users\\<my-user>\\AppData\\Roaming\\pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = true
keyring.enabled = true
python.installation-dir = "{data-dir}\\python" # C:\Users\<my-user>\AppData\Roaming\pypoetry\python
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}\\virtualenvs" # C:\Users\<my-user>\AppData\Local\pypoetry\Cache\virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false
Python Sysconfig
sysconfig.log
Platform: "win-amd64"
Python version: "3.13"
Current installation scheme: "nt"
Paths:
data = "C:\Program Files\Python313"
include = "C:\Program Files\Python313\Include"
platinclude = "C:\Program Files\Python313\Include"
platlib = "C:\Program Files\Python313\Lib\site-packages"
platstdlib = "C:\Program Files\Python313\Lib"
purelib = "C:\Program Files\Python313\Lib\site-packages"
scripts = "C:\Program Files\Python313\Scripts"
stdlib = "C:\Program Files\Python313\Lib"
Variables:
BINDIR = "C:\Program Files\Python313"
BINLIBDEST = "C:\Program Files\Python313\Lib"
EXE = ".exe"
EXT_SUFFIX = ".cp313-win_amd64.pyd"
INCLUDEPY = "C:\Program Files\Python313\Include"
LDLIBRARY = "python313.dll"
LIBDEST = "C:\Program Files\Python313\Lib"
LIBDIR = "C:\Program Files\Python313\libs"
LIBRARY = "python313.dll"
Py_GIL_DISABLED = "0"
SOABI = "cp313-win_amd64"
TZPATH = ""
VERSION = "313"
VPATH = "..\.."
abi_thread = ""
abiflags = ""
base = "C:\Program Files\Python313"
exec_prefix = "C:\Program Files\Python313"
implementation = "Python"
implementation_lower = "python"
installed_base = "C:\Program Files\Python313"
installed_platbase = "C:\Program Files\Python313"
platbase = "C:\Program Files\Python313"
platlibdir = "DLLs"
prefix = "C:\Program Files\Python313"
projectbase = "C:\Program Files\Python313"
py_version = "3.13.3"
py_version_nodot = "313"
py_version_nodot_plat = "313"
py_version_short = "3.13"
srcdir = "C:\Program Files\Python313"
userbase = "C:\Users\<my-user>\AppData\Roaming\Python"
Example pyproject.toml
Poetry Runtime Logs
poetry-runtime.log
PS C:\Users\<my-user>\Documents\<my-project>> poetry -vvv env info
Loading configuration file C:\Users\<my-user>\AppData\Roaming\pypoetry\config.toml
Stack trace:
2 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\base_env.py:430 in _run
428│ else:
429│ encoding = "locale" if sys.version_info >= (3, 10) else None
→ 430│ output = subprocess.check_output(
431│ cmd, stderr=stderr, env=env, text=True, encoding=encoding, **kwargs
432│ )
1 C:\Program Files\Python313\Lib\subprocess.py:472 in check_output
470│ kwargs['input'] = empty
471│
→ 472│ return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
473│ **kwargs).stdout
474│
CalledProcessError
Command '['C:\\Users\\<my-user>\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\<my-project>-<some-poetry-generated-string>-py3.13\\Scripts\\python.exe', '-I', '-W', 'ignore', '-c', 'import sys\n\nif hasattr(sys, "real_prefix"):\n print(sys.real_prefix)\nelif hasattr(sys, "base_prefix"):\n print(sys.base_prefix)\nelse:\n print(sys.prefix)\n']' returned non-zero exit status 1.
at C:\Program Files\Python313\Lib\subprocess.py:577 in run
573│ # We don't call process.wait() as .__exit__ does that for us.
574│ raise
575│ retcode = process.poll()
576│ if check and retcode:
→ 577│ raise CalledProcessError(retcode, process.args,
578│ output=stdout, stderr=stderr)
579│ return CompletedProcess(process.args, retcode, stdout, stderr)
580│
581│
The following error occurred when trying to handle this error:
Stack trace:
13 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:327 in run
325│
326│ try:
→ 327│ exit_code = self._run(io)
328│ except BrokenPipeError:
329│ # If we are piped to another process, it may close early and send a
12 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\console\application.py:260 in _run
258│ with directory(self._working_directory):
259│ try:
→ 260│ exit_code = super()._run(io)
261│ except PoetryRuntimeError as e:
262│ io.write_error_line("")
11 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:431 in _run
429│ io.input.interactive(interactive)
430│
→ 431│ exit_code = self._run_command(command, io)
432│ self._running_command = None
433│
10 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:473 in _run_command
471│
472│ if error is not None:
→ 473│ raise error
474│
475│ return terminate_event.exit_code
9 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:457 in _run_command
455│
456│ if command_event.command_should_run():
→ 457│ exit_code = command.run(io)
458│ else:
459│ exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED
8 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\commands\base_command.py:117 in run
115│ io.input.validate()
116│
→ 117│ return self.execute(io) or 0
118│
119│ def merge_application_definition(self, merge_args: bool = True) -> None:
7 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\commands\command.py:61 in execute
59│
60│ try:
→ 61│ return self.handle()
62│ except KeyboardInterrupt:
63│ return 1
6 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\console\commands\env\info.py:31 in handle
29│ from poetry.utils.env import EnvManager
30│
→ 31│ env = EnvManager(self.poetry).get()
32│
33│ if self.option("path"):
5 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\env_manager.py:249 in get
247│ return self.get_system_env()
248│
→ 249│ return VirtualEnv(venv)
250│
251│ if env_prefix is not None:
4 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\virtual_env.py:40 in __init__
38│ # from inside the virtualenv.
39│ if base is None:
→ 40│ output = self.run_python_script(GET_BASE_PREFIX)
41│ self._base = Path(output.strip())
42│
3 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\base_env.py:404 in run_python_script
402│ # This is useful to prevent user site being disabled over zealously.
403│
→ 404│ return self.run(
405│ self._executable,
406│ "-I",
2 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\base_env.py:389 in run
387│ def run(self, bin: str, *args: str, **kwargs: Any) -> str:
388│ cmd = self.get_command_from_bin(bin) + list(args)
→ 389│ return self._run(cmd, **kwargs)
390│
391│ def run_pip(self, *args: str, **kwargs: Any) -> str:
1 ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\virtual_env.py:90 in _run
88│ def _run(self, cmd: list[str], **kwargs: Any) -> str:
89│ kwargs["env"] = self.get_temp_environ(environ=kwargs.get("env"))
→ 90│ return super()._run(cmd, **kwargs)
91│
92│ def get_temp_environ(
EnvCommandError
Command ['C:\\Users\\<my-user>\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\<my-project>-<some-poetry-generated-string>-py3.13\\Scripts\\python.exe', '-I', '-W', 'ignore', '-c', 'import sys\n\nif hasattr(sys, "real_prefix"):\n print(sys.real_prefix)\nelif hasattr(sys, "base_prefix"):\n print(sys.base_prefix)\nelse:\n print(sys.prefix)\n'] errored with the following return code 1
Error output:
Traceback (most recent call last):
File "C:\Program Files\Python313\Lib\linecache.py", line 228, in _register_code
for const in code.co_consts:
^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'co_consts'
at ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\base_env.py:434 in _run
430│ output = subprocess.check_output(
431│ cmd, stderr=stderr, env=env, text=True, encoding=encoding, **kwargs
432│ )
433│ except CalledProcessError as e:
→ 434│ raise EnvCommandError(e)
435│
436│ return output
437│
438│ def execute(self, bin: str, *args: str, **kwargs: Any) -> int:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with poetry/utils/env/base_env.py and poetry/utils/env/virtual_env.py, following the env info entry point in poetry/console/commands/env/info.py and the GET_BASE_PREFIX subprocess call shown in the traceback. Reproduce the failure after a Python 3.13.2-to-3.13.3 update and determine the expected handling for an existing virtual environment. Done means affected Poetry commands either continue working or provide an actionable error instead of the raw traceback.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100