What to do if an error occurs when loading a python project created with poetry into VS Code

Introduction

When I loaded the Poetry environment into VS Code, I got an import error. After that, the error was resolved safely, but I'm addicted to it, so I'll leave a note.

environment

Mac mojave

Why it happens

The default behavior of Poetry is to create a virtual environment according to the settings. I don't know that in VSCode, so even if I ignore poetry and try to read it, the library cannot be found at all and an error occurs because it cannot be solved.

Then what to do

It is necessary to change the settings and recreate the poetry environment. Poetry seems to be a specification that prioritizes reading the environment once it is created, so it will not be as I thought I would not recreate it by taking steps.

1: Confirm setting

First, check the poetry settings. The important thing here is virtualenvs.in-project. If you get an error, I think this is false.

This setting is where to place the poetry installation, and if it is false, it will be stored in the folder set in virtualenvs.path. "

$ poetry config --list
cache-dir = "/Users/tasogarei/Library/Caches/pypoetry"
virtualenvs.create = true
virtualenvs.in-project = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /Users/tasogarei/Library/Caches/pypoetry/virtualenvs

2: Change settings

Change virtualenvs.in-project to true. This setting is to place the part to be installed by poetry in the root folder of the project, and by setting it to true, it will be placed in the root folder.

$ poetry config virtualenvs.in-project true

3: Delete existing

Once created with the poetry specifications, even if the settings are changed, the file before the change will be viewed. Therefore, there is no point in changing it unless you delete the folder in virtualenvs.path.

So, please delete the entire folder of the project you want to read in the corresponding folder.

4: Package installation by poetry

Now that you are ready, install the package again. I started over from ʻinit just in case, but I don't need ʻinit.

$ poetry install

5: Confirm with VS Code

When ʻinstall is complete, a .venv` folder will be created at the root. From now on, the package will be in here, and VS Code will read this folder nicely (no additional settings required), so I think the error disappears when you start it.

This completes the work.

Recommended Posts

What to do if an error occurs when loading a python project created with poetry into VS Code
What to do if an error occurs when importing numpy with VScode
What to do if you get an error when installing python with pyenv
What to do when an error occurs with import _ssl
What to do if you get an OpenSSL error when installing Python 2 with pyenv
[Beanstalk] What to do when an error occurs with import uuid
What to do if pip --user returns an error in a virtual environment created with pyenv
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
[python] What to do when an error occurs in send_keys of headless chrome
What to do if a Unicode Encode Error occurs in Sublime Text Python
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
What to do when a Remove Error occurs when updating conda
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do if you run python in IntelliJ and end with an error
What to do if a communication error occurs due to proxy when installing with package management of pip, npm, gem
What to do if you get an Undefined error when trying to use pip with pyenv
What to do if you couldn't send an email to Yahoo with Python.
What to do if pyenv install does not proceed with an error
[Python] What to do when an error related to SSL authentication is returned
What to do if you get an error when trying to load mnist
What to do if you get an error when installing Dlib (Ubuntu)
[OSX] [pyenv] What to do when an SSL error occurs in pip
What to do if you get a "Wrong Python Platform" warning when using Python with the NetBeans IDE
[Django] What to do if an Integrity Error occurs when registering data from the management site to the database
What to do if a symbolic link error occurs in import cv while trying to install OpenCV in Python
What to do if a version error occurs in the selenium Chrome driver
What to do if an SSL connection error (ssl.SSLError: [SSL: DH_KEY_TOO_SMALL]) occurs on Ubuntu 20.04
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
What to do if a UnicodeDecodeError occurs in pip
A memorandum when an error occurs with pip install
What to do if the print command itself causes an error in Maya python
What to do if Python IntelliSense is not displayed in VS Code on Windows
A story about an error when loading a TensorFlow model created with Google Colab locally
A convenient function memo to use when you want to enter the debugger if an error occurs when running a Python script.
What to do if you get an error when running "certbot renew" in CakePHP environment
[Small story] What to do if "Error with child process: Building resource'awsToolkitSamLocalResource'" does not work when Lambda is locally executed by SAM from VS Code
What to do with PYTHON release?
What to do if you can't install pyaudio with pip #Python
What to do if you get a minus zero in Python
What to do if Insecure Platform Warning appears when running Python
What to do if you can't build your project with Maven
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
What to do if you get a must override `get_config` error when trying to model.save in Keras
I built an environment from centos installation to php source expansion on linux, but what to do when a browser error occurs
Prepare a Python virtual environment for your project with venv with VS Code
What to do if there is a decimal in python json .dumps
What to do if you get an error like'Qstring' has already been set to version 1 using mne python
What to do if ipython and python start up with different versions
I was addicted to creating a Python venv environment with VS Code
Steps to create a Python virtual environment with VS Code on Windows
[Python / Pandas] A bug occurs when trying to replace a DataFrame with `None` with` replace`
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb
How to write what to do when an application is first displayed in Qt for Python with Designer
What to do if the server doesn't start with python manage.py runserver
What to do if you get a TypeError with numpy min, max
What to do if you get a Permission denied (public key) error when trying to pull on Github
[Python] What to do if you get a ModuleNotFoundError when importing pandas using Jupyter Notebook in Anaconda
What to do if fprintd requires a password when registering your fingerprint
What to do if an error occurs in TensorFlow RNN related import or RNN (LSTM) Cell (v 0.11r ~)
What to do when psycopg2 throws an error when pipenv lock under Pipenv environment