Skip to content

Instantly share code, notes, and snippets.

@mpaloni
Last active November 5, 2024 08:18
Show Gist options
  • Save mpaloni/156b5f6d2b381d7a88785d41aeaa63d9 to your computer and use it in GitHub Desktop.
Save mpaloni/156b5f6d2b381d7a88785d41aeaa63d9 to your computer and use it in GitHub Desktop.
poetry

Install poetry

https://python-poetry.org/docs/#installation

pipx install poetry

Can also pipx upgrade poetry or pipx uninstall poetry

poetry env use 3.9

Activate correct Python version

Make sure that your terminal folder is located in project root. Then run following command:

poetry env use 3.9

Add to project

Original: https://stackoverflow.com/questions/59882884/vscode-doesnt-show-poetry-virtualenvs-in-select-interpreter-option

You just need to type in your shell:

poetry config virtualenvs.in-project true

The virtualenv will be created inside the project path and vscode will recognize. Consider adding this to your .bashrc or .zshrc.

If you already have created your project, you need to re-create the virtualenv to make it appear in the correct place:

poetry env list  # shows the name of the current environment
poetry env remove <current environment>
poetry install  # will create a new environment using your updated configuration

Remember the install path for following step.

Set interpreter in vscode

Original: https://stackoverflow.com/questions/66869413/visual-studio-code-does-not-detect-virtual-environments

  1. In VSCode open your command palette — Ctrl+Shift+P by default

  2. Look for Python: Select Interpreter

  3. In Select Interpreter choose Enter interpreter path... and then Find...

  4. Navigate to your venv folder — eg, ~/pyenvs/myenv/ or \Users\Foo\Bar\PyEnvs\MyEnv\

  5. In the virtual environment folder choose /bin/python or /bin/python3

Run interactive code

https://superuser.com/questions/1461655/vs-code-shiftenter-does-not-send-code-to-python-interactive-why

If you go to the Settings( Ctrl + , ) you can see the search bar. There, put in 'Send Selection To Interactive Window' or the like, and click the checkbox of 'Python › Data Science: Send Selection To Interactive Window'. After that, you would be able to run certain lines directly in the Interactive Window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment