I was researching various things because I wanted to use python on Windows, but I went back and forth when building the environment, so I will output it as a memorandum. Write the code in VS code.
・ Windows 10 Home ・ Visual Studio Code
As a prerequisite, make sure that python itself is installed on Windows. You can install it from here. This is the official page of python japan.
For Windows, open powershell as an administrator,
Set-ExecutionPolicy RemoteSigned
Type the command. This allows the script to run only on local files. There are other options, so if you are interested, please refer to here.
Then, in VScode's terminal, create and move the directory you want to work in.
$ mkdir test
$ cd test
Create a virtual environment directly under the test directory. Actually, this is the only place where I got stuck, but in my environment, when I typed the following command, it entered the virtual environment obediently.
$ py -m venv myenv
$ myenv/Scripts/Activate.ps1
Change "myenv" to any character string.
Depending on the site, py was python or python3, and there were a lot of commands lined up, and even if I typed it, it didn't work or I was angry.
Then, when I was looking at the python japan page, I was wondering why the py command works, and there was a description like this.
For the Windows version of Python, the Python launcher py is recommended over using the python command. Normally, when you run Python from the command line, you need to record the directory where you installed Python in a system setting called an environment variable, but py can be run without any settings.
If you want to use the python command, please pass the path in each environment, but is it okay to recognize that the py command can be used by default?
Anyway, if you type the above, you should see (myenv) on the left side of the terminal. You are now in the virtual environment.
By the way, the command to exit the virtual environment is
$ deactivate
is.
It is necessary to continue to make settings on the VScode side, but since some people have already written an article, please refer to here to make settings. The content is to run Django in a virtual environment, but I think that it is okay if you make the same settings for other frameworks.
Recommended Posts