In the experiment, I was told to paste the code into Jupyter notebook and execute the program, so it was annoying. So I thought I'd write it in Qiita, which runs Python in the conda environment on VS Code.
macOS Mojave 10.14.4
Visual Studio Code 1.47.1
Anaconda-Navigator 1.9.12
(Maybe Windows is the same way.)
Install Anaconda (see others) Install VS Code (see others) From extensions Python: Python extensions Install
Run VS Code from Anaconda navigator Select an environment with VS Code Run python file
Launch Anaconda navigator and launch VS Code from the main screen. Now you can run it in VS Code.
Digression conda is a kind of virtual environment, and you can easily create a different version of the environment other than root. It is easier to build an environment in a virtual environment when it does not work in the latest version environment (for example, when only python2 system is used). You can open it in VS Code in a similar way.
Select an environment with VS Code
Next, open VS Code and click on the place where Python ~ is written at the bottom left.
Select an environment. In this part you choose which environment to use to run python. This time, select the created Python 3.7 (conda: base).
You have now selected the virtual environment within conda. Finally run the file.
File execution
This time, we will use the debug function. Click the bug mark (debug) on the left side of VS Code.
When you click Run, you will be presented with a selection of device environments, select Python File Debug.
You have now executed the Python file. You should see the results returned in the command window below.
If you run it with Jupyter, you will have to move it to a py file at the time of submission, or you will paste the same code into cells and you will not know which is the latest (experienced person), so use VSCode! With Anaconda, you can run py files using Spyder or something, but I personally like VS Code, so I recommend running it with VS Code.
I think that VS Code is doing the mess with this command.
$ conda activate (Environment name)
Enter the virtual environment
(Environment name)$ python3 (file name).py
Run Python in a virtual environment.
I think it's like bashing around here.
I was a little scared because the procedure manual of the experiment described how to install using pip with conda. (Experienced person)
Recently, VS Code has become so convenient that other editors have become unthinkable, so I think I'll try using Xcode once in a while. VS Code is very useful.
The rest is a digression, but you can use Jupyter Notebook with VS Code. When writing code in a browser, you can't use the functions customized for yourself by storing the code or extending the VS Code, so use Jupyter Notebook with VS Code.
It's very easy to do. Right-click on the .ipynb file → open it in this application → easily open it in Visual Studio Code
Since it can be used on VSCode in the same way as a browser, you can compare the result of googled the error message with the two codes without tabs.
This page is very easy to understand when it comes to creating notebooks from scratch. https://dev.classmethod.jp/articles/visual-studio-code-jupyter-notebook/ (Python on VS Code: Python extension needs to be added)
Recommended Posts