This is the first post. Until now, I used notepad ++ to write code, but I decided to use VScode because it was convenient. It's for studying python, but I created an environment because I wanted to make it easier to manage by using pipenv. However, the warning did not disappear and I had a lot of trouble, so I will leave it here as a memorandum.
The environment to be built this time is as follows. -OS:windows10 -Python:3.8 -Library used: pipenv, Django
Please install the one that suits your environment from the following page. https://code.visualstudio.com/download
Please download and install the version you want according to the environment from the following page. https://www.python.org/downloads/windows/ Also, in the case of windows, there should be a checkbox to add an environment variable in the middle, so don't forget to check it. (There is a checkbox for words like "Add pythonX.X to PATH".) After installing, let's confirm that the installation is completed with the following command.
python --version
If the version information is displayed, it means that the installation was successful. (If the PATH does not pass, the command will not be recognized here.)
Let's install it from 2 as it is. Execute the following command.
pip install pipenv
After installing pipenv, add environment variables. Add the following environment variable and set the value to "true".
PIPENV_VENV_IN_PROJECT
By doing this, when you create a virtual environment with pipenv, a ".venv" folder will be created in the working directory. If you do not add this environment variable, it will be created under the user folder. There is still no problem, but it is recommended to set it because it is troublesome when managing the environment and folders on VScode later.
python extension for visual studio code
.venv,
If you set this, it seems that when you open the workspace, it will load the .venv folder directly under it. 3. Restart VScode once. Load the settings up to this point. 4. We will create the environment in earnest from here. Open the folder you work in from "File"-> "Open Folder". 5. Select "Terminal"-> "New Terminal" to open the terminal. 6. Create a virtual environment with pipenv. Execute the following command in the terminal.
pipenv install
At this time, you will be asked in English something like "It looks like a virtual environment was created, but do you want to use it?", So select "YES". Then, I think that the folder structure will be as follows.
.
├─.venv ← Made with pipenv
├─.vscode ← Created by clicking Yes
├─Pipfile ← Made with pipenv
└─Pipfile.lock ← Made with pipenv
If .vscode was not created (or if you click No), create a .py file with an appropriate name directly under the workspace. Then it should be made. 7. Create a folder named ".env" directly under the workspace and write the following.
PYTHONPATH=.venv/src
"python.envFile": "${workspaceFolder}\\.env"
Don't forget to double the backslash as it will be recognized as an escape key. By following steps 7 and 8, you will not be able to load the library in the virtual environment and get a warning.
later
pipienv install xxx
Install your favorite library with
pipenv shell
You can develop in your favorite virtual environment by executing! that's all! Thank you for your hard work!
Until now, I didn't really care about it because I just wanted to type the code, but depending on the site, vscode is standard and it is convenient to link with git, so I started using it. From the point of writing this article, the eraser in my head is still working hard today I created it while struggling with the disappearing memories.
Do you know this too? Not here
If you have any questions, please let us know. Thank you to all of our ancestors.
Recommended Posts