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.

poetry shell failing to set up my .venv local environment

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

My project is set up to use in-project virtual environments. My poetry.toml:

[virtualenvs]
in-project = true

I make sure that my envs are empty:

$ poetry env list
# envs are empty

I install the dependencies, and it creates the .venv directory in the root of my project. The command appears to complete successfully, but there is a problem.

$ poetry install

The problem is that virtual env shell did not initiate. It doesn’t have the (.venv) prefix in my terminal.

If I try poetry shell I get the following warning:

$ poetry shell
The virtual environment found in /home/pomatti/pjs/azure/azure-multiregion-aks-cluster/microservices/utils/.venv seems to be broken.

It appears to be broken. But why didn’t it tell me so in the previous command?

Now if I exit and try again, then it shows what it seems to be the root cause:

$ exit
exit
pomatti@DESKTOP-DP18TG3:~/pjs/azure/azure-multiregion-aks-cluster/microservices/utils$ poetry shell
The virtual environment found in /home/pomatti/pjs/azure/azure-multiregion-aks-cluster/microservices/utils/.venv seems to be broken.
Recreating virtualenv aksmr-utils in /home/pomatti/pjs/azure/azure-multiregion-aks-cluster/microservices/utils/.venv
Spawning shell within /home/pomatti/pjs/azure/azure-multiregion-aks-cluster/microservices/utils/.venv
pomatti@DESKTOP-DP18TG3:~/pjs/azure/azure-multiregion-aks-cluster/microservices/utils$ . /home/pomatti/pjs/azure/azure-multiregion-aks-cluster/microservices/utils/.venv/bin/activate
bash: /home/pomatti/pjs/azure/azure-multiregion-aks-cluster/microservices/utils/.venv/bin/activate: No such file or directory

It is trying to to call .venv/bin/activate which doesn’t exist, because it has been created as .venv/local/bin/activate. Why?

Now to add to this whole thing, even if I manually activate it with source .venv/local/bin/activate, VS Code is not recognizing the environment, and I also can’t add new packages.

$ poetry add azure.identity
The virtual environment found in /home/pomatti/pjs/azure/azure-multiregion-aks-cluster/microservices/utils/.venv seems to be broken.
Recreating virtualenv aksmr-utils in /home/pomatti/pjs/azure/azure-multiregion-aks-cluster/microservices/utils/.venv

  FileNotFoundError

  [Errno 2] No such file or directory: '/home/pomatti/pjs/azure/azure-multiregion-aks-cluster/microservices/utils/.venv/local/bin/python3'

  at ~/.poetry/lib/poetry/_vendor/py3.10/virtualenv/discovery/builtin.py:91 in propose_interpreters
       87│ 
       88│     # 1. if it's a path and exists
       89│     if spec.path is not None:
       90│         try:
    →  91│             os.lstat(spec.path)  # Windows Store Python does not work with os.path.exists, but does for os.lstat
       92│         except OSError:
       93│             if spec.is_abs:
       94│                 raise
       95│         else:

What is going on?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
abncommented, May 30, 2022

Thanks for closing the loop (again) @epomatti. Much appreciated. 💜

1reaction
abncommented, May 28, 2022

Odd. Thanks for closing the loop @epomatti .

Read more comments on GitHub >

github_iconTop Results From Across the Web

The virtual environment found seems to be broken | python ...
Go to your project directory and start Poetry (if you're not already there); get rid of the broken virtual environment, · Leave Poetry...
Read more >
Python Virtual Environments: A Primer
In this tutorial, you'll learn how to work with Python's venv module to create and manage separate virtual environments for your Python ...
Read more >
Python Virtual Environments tutorial using Virtualenv and Poetry
A mini-guided Python tutorial showing how to use virtual environment and why it's matters on virtualenv and poetry illustrated examples.
Read more >
Installing and using virtualenv with Python 3
Virtualenv is a tool used to create an isolated Python environment. This environment has its own installation directories that doesn't share ...
Read more >
Using Python environments in VS Code
If you are creating an environment using Venv, the command presents a list of ... We recommend you install a Python interpreter into...
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