                  t))
       (python-isort-on-save-mode 1))))
 
+(defun python-poetry-virtualenv-path ()
+  (with-temp-buffer
+    (if (condition-case err
+            (zerop (call-process "poetry" nil t nil "env" "info" "-p"))
+          (error (minibuffer-message "%s" (error-message-string err)) nil))
+        (string-trim (buffer-string))
+      nil)))
+
 (add-hook 'python-mode-hook
           (lambda ()
             ;; Set `python-shell-interpreter'
             (when (python-use-poetry-p)
-              (make-local-variable 'python-shell-interpreter)
-              (setf python-shell-interpreter
-                    (with-temp-buffer
-                      (if (condition-case err
-                              (zerop (call-process "poetry" nil t nil "run" "which" "python"))
-                            (error (message "%s" (error-message-string err)) nil))
-                          (string-trim (buffer-string))
-                        nil))))
+              (when-let ((virtualenv-root (python-poetry-virtualenv-path)))
+                (make-local-variable 'python-shell-interpreter)
+                (make-local-variable 'python-shell-virtualenv-root)
+                (setf python-shell-interpreter (concat virtualenv-root "/bin/python")
+                      python-shell-virtualenv-root virtualenv-root)))
 
             (with-eval-after-load 'dap-python
               (setf dap-python-executable python-shell-interpreter))

  (when (and (buffer-file-name)
             (derived-mode-p 'python-mode))
    (let* ((buf-file (buffer-file-name))
           (root (and (functionp 'projectile-acquire-root)
                      (projectile-acquire-root (file-name-directory buf-file)))))

      (when (and root
                 (not (seq-some (lambda (buf)

            (lambda ()
              (add-hook 'before-save-hook 'gofmt-before-save nil 'local)
              (with-eval-after-load 'lsp-mode
                (remove-hook 'before-save-hook 'gofmt-before-save 'local)
                (add-hook 'lsp-managed-mode-hook
                          (lambda ()
                            (if lsp-managed-mode
                                (progn
                                  (setq-local lsp-enable-indentation t
                                              lsp-enable-on-type-formatting t)
                                  (add-hook 'before-save-hook 'lsp-go-format-buffer nil 'local))
                              (kill-local-variable 'lsp-enable-indentation)
                              (kill-local-variable 'lsp-enable-on-type-formatting)
