Search code examples
pythonpytestpython-poetry

poetry looking for virtualenv that isn't there


I'm new to Python and I'm trying to install a projects dependencies for the first time and run the unit tests provided.

The project uses poetry and pytest. I've successfully done a fresh install of poetry on my Windows machine following the instructions on the website but when trying to install dependencies using poetry install it gives the following error:

  EnvCommandError

  Command C:\Users\jon.doe\AppData\Local\pypoetry\Cache\virtualenvs\my-project-d9FwOK5-py3.8\Scripts\python.exe - errored with the following return code 1, and output:
  The system cannot find the path specified.
  input was : import sys

  if hasattr(sys, "real_prefix"):
      print(sys.real_prefix)
  elif hasattr(sys, "base_prefix"):
      print(sys.base_prefix)
  else:
      print(sys.prefix)


  at ~\.poetry\lib\poetry\utils\env.py:1101 in _run
      1097│                 output = subprocess.check_output(
      1098│                     cmd, stderr=subprocess.STDOUT, **kwargs
      1099│                 )
      1100│         except CalledProcessError as e:
    → 1101│             raise EnvCommandError(e, input=input_)
      1102│
      1103│         return decode(output)
      1104│
      1105│     def execute(self, bin, *args, **kwargs):

C:\Users\jon.doe\AppData\Local\pypoetry doesn't exist so that's why it can't find the virtualenv. My config is set to create a virtualenv if one doesn't exist (as it is by default, I've changed nothing).

Why is it looking in the wrong place and how do I get a virtualenv connected and up and running for this project?


Solution

  • In the end Poetry wasn't the issue. My copy of Windows came with a "python.exe" Python installer that had an environment variable that was causing problems - removing it fixed the issue.