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

Activate poetry virutal env in VSCode on Windows 10 #1136

Closed
3 tasks done
alex-lechner opened this issue May 29, 2019 · 10 comments
Closed
3 tasks done

Activate poetry virutal env in VSCode on Windows 10 #1136

alex-lechner opened this issue May 29, 2019 · 10 comments
Labels
area/cli Related to the command line

Comments

@alex-lechner
Copy link

alex-lechner commented May 29, 2019

  • 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).
  • OS version and name: Windows 10
  • Poetry version: 0.12.16
  • Link of a Gist with the contents of your pyproject.toml file: N/A

Issue

I have an issue on Windows 10 when trying to activate the virtual environment. I use Visual Studio Code and I have configured the Terminal of VSCode to use git bash. So when I open the Visual Studio code terminal an execute poetry shell -vvv I get

Using virtualenv: C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\my-project-py3.7
Spawning shell within C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\my-project-py3.7

[RuntimeError]
Unable to detect the current shell.

Exception trace:
 C:\Users\user\.poetry\lib\poetry\_vendor\py3.7\cleo\application.py in run() at line 94
   status_code = self.do_run(input_, output_)
 C:\Users\user\.poetry\lib\poetry\console\application.py in do_run() at line 88
   return super(Application, self).do_run(i, o)
 C:\Users\user\.poetry\lib\poetry\_vendor\py3.7\cleo\application.py in do_run() at line 197
   status_code = command.run(input_, output_)
 C:\Users\user\.poetry\lib\poetry\console\commands\command.py in run() at line 77
   return super(BaseCommand, self).run(i, o)
 C:\Users\user\.poetry\lib\poetry\_vendor\py3.7\cleo\commands\base_command.py in run() at line 146
   status_code = self.execute(input_, output_)
 C:\Users\user\.poetry\lib\poetry\_vendor\py3.7\cleo\commands\command.py in execute() at line 107
   return self.handle()
 C:\Users\user\.poetry\lib\poetry\console\commands\shell.py in handle() at line 40
   shell = Shell.get()
 C:\Users\user\.poetry\lib\poetry\utils\shell.py in get() at line 37
   raise RuntimeError("Unable to detect the current shell.")

shell

Activating the environment seems to work when I open the command prompt outside of VSCode BUT there's no tag in the terminal that indicates an active environment. With tag I mean instead of

 C:\Users\user>

the terminal should look like this:

 (my-project-py37) C:\Users\user>

However, the tag (I don't know if it's the proper name) appears if I do the following:

  1. Execute poetry debug:info in the project folder in the command prompt
  2. Copy the value after * Path: from the output of the command in step 1
  3. Append \Scripts\activate to the copied value from step 2 like so C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\my-project-py37\Scripts\activate and hit enter in the command prompt

Any solutions for this? I really want to use poetry from the git bash terminal in VSCode so any help with this would be awesome. Thanks!

@stale
Copy link

stale bot commented Nov 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 13, 2019
@alex-lechner
Copy link
Author

I'm on MacOS now but this issue is still not resolved.

@stale stale bot removed the stale label Nov 13, 2019
@faulander
Copy link

Same problem here, Windows 10, latest Version of Poetry. But it's not a problem of Visual Studio Code for me. It also happens on an outside shell:
image

@pwildenhain
Copy link

Also having this issue on Windows 10 with the latest version of poetry

@finswimmer finswimmer added area/cli Related to the command line status/triage This issue needs to be triaged labels May 17, 2020
@abn
Copy link
Member

abn commented May 9, 2022

Can you try the latest releases? See if #2147 fixed this?

@pwildenhain
Copy link

I've tested this with the latest release and it doesn't seem like anything has changed regarding this issue

PS C:\Users\wildenhp\drive> poetry shell
Spawning shell within C:\Users\wildenhp\drive\.venv
Microsoft Windows [Version 10.0.19043.1645]
(c) Microsoft Corporation. All rights reserved.

C:\Users\wildenhp\drive>poetry --version
Poetry version 1.1.13

@abn
Copy link
Member

abn commented May 10, 2022

@pwildenhain looks like you no longer have the "cannot detect shell" error when executing poetry shell reported in the issue. The lack of prompt is likely a virtualenv issue not a poetry one.

If you are using 1.1.13 installed via get-poetry.py, I would recommend reinstalling it via the new script to ensure you get a newer version of virtualenv. Once that is done, recreate your environment.

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python - --uninstall
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -

You could also try the verison on master.

@pwildenhain
Copy link

You are correct, maybe I'll look more down the virtualenv path -- thanks!

@abn
Copy link
Member

abn commented May 10, 2022

Closing this for now based on above comments.

@abn abn closed this as completed May 10, 2022
@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Jun 11, 2022
Copy link

github-actions bot commented Mar 1, 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 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/cli Related to the command line
Projects
None yet
Development

No branches or pull requests

6 participants