2

I've installed python10 on my windows machine. I've installed poetry. Both python and poetry run from the command line.

I clone a poetry enabled repository (this project works correctly on another machine). I've updated the myproject.toml file to 3.10

[tool.poetry.dependencies]
python = "^3.10"
defusedxml = "^0.7.1"
jsondiff = "^1.3.0"
pytz = "^2021.1"

run poetry update

I then run the project in the visual studio debugger.

and it fails with

Exception has occurred: ModuleNotFoundError
No module named 'pytz'

pytz appears in my poetry.lock

poetry show lists it

pytz                      2021.3   World timezone definitions, modern and historical

What am I missing?

Laurent
  • 12,287
  • 7
  • 21
  • 37
MrD at KookerellaLtd
  • 2,412
  • 1
  • 15
  • 17

1 Answers1

2

You might need to select a different Python interpreter first.  That is, you need to tell VS Code to use the Python interpreter inside the poetry virtual environment.  See if the following works:

Setup

  1. Open up VS Code

  2. Open up the terminal/PowerShell in VS Code ( keyboard shortcut: Ctrl + `  )

  3. Change your directory to be the folder where your project is ( ie, where the pyproject.toml and poetry.lock files are ).  This is normally done with a terminal/PowerShell command like cd ./path/to/my_project_folder

Changing interpreter

  1. Open the command pallet ( keyboard shortcut: Ctrl + Shift + P or F1 )

  2. Search for "python: select interpreter" and select it with the mouse or navigate with the arrow keys and press Enter

  3. Select "Enter interpreter path..."

  4. Go back to the terminal/PowerShell ( keyboard shortcut: Ctrl + `  )

  5. Type poetry env info --path and press Enter.  ( Note: if nothing shows up, then you need to create a virtualenv by typing poetry shell into the terminal/PowerShell first.  Then repeat step 8. )

  6. Copy and paste the result of step 8 into the prompt box at the top that says "Enter path to a Python interpreter" and press Enter

Extra: Using VS Code debugger inside of Poetry

If you'd like to use the VS Code debugger for this Poetry project, then continue to do the following:

  1. Open up the .py file in your project that you want to debug

  2. Set any break points by clicking to the left of the line numbers ( a red circle should appear for any break points you set )

  3. Start the debugger ( keyboard shortcut: F5 )

  4. Step through the program ( keyboard shortcut: F11 )

  5. Enjoy! ^.^