Skip to content
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

poetry shell failing to set up my .venv local environment #5690

Closed
3 tasks done
epomatti opened this issue May 26, 2022 · 10 comments
Closed
3 tasks done

poetry shell failing to set up my .venv local environment #5690

epomatti opened this issue May 26, 2022 · 10 comments
Labels
area/venv Related to virtualenv management kind/bug Something isn't working as expected

Comments

@epomatti
Copy link

  • 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?

@epomatti epomatti added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels May 26, 2022
@abn
Copy link
Member

abn commented May 26, 2022

@epomatti can you try manually creating a virtual env and see what you get?

# if you are using a specific python binary, use that instead 
python -m pip install virtualenv
python -m virtualenv venv-test

And maybe also post the output of python -m site.

It is likely that sys.prefix is incorrectly used when creating the venv.

@abn abn added status/waiting-on-response Waiting on response from author area/venv Related to virtualenv management labels May 26, 2022
@epomatti
Copy link
Author

@abn I got this

image

And the site:

$ python3 -m site
sys.path = [
    '/home/pomatti/pjs/azure/azure-multiregion-aks-cluster/microservices/utils',
    '/usr/lib/python310.zip',
    '/usr/lib/python3.10',
    '/usr/lib/python3.10/lib-dynload',
    '/home/pomatti/.local/lib/python3.10/site-packages',
    '/usr/local/lib/python3.10/dist-packages',
    '/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/pomatti/.local' (exists)
USER_SITE: '/home/pomatti/.local/lib/python3.10/site-packages' (exists)
ENABLE_USER_SITE: True

@abn
Copy link
Member

abn commented May 26, 2022

@epomatti from what I can tell, the issue is most likely with virtualenv. Poetry simply uses virtualenv to create a new environment (similar to what you did to create the environment manualy).

@epomatti
Copy link
Author

epomatti commented May 26, 2022

@abn I'll keep reading venv docs. In the meanwhile I opened an SO and will report here if I find it. Looks like we can close it.

https://stackoverflow.com/q/65390129/3231778

@epomatti
Copy link
Author

This creates the subdirectories accordingly. Will try to figure out why.

python3 -m venv .venv

@epomatti
Copy link
Author

I ended up re-creating my Ubuntu installation it works normally now.

@abn
Copy link
Member

abn commented May 28, 2022

Odd. Thanks for closing the loop @epomatti .

@epomatti
Copy link
Author

@abn here is the explanation: pypa/setuptools#3278

Case closed.

@abn
Copy link
Member

abn commented May 30, 2022

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

@mkniewallner mkniewallner removed status/triage This issue needs to be triaged status/waiting-on-response Waiting on response from author labels Jun 11, 2022
Copy link

github-actions bot commented Mar 2, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/venv Related to virtualenv management kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

3 participants