Use Python in Anaconda environment with VS Code

What is this?

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.

environment

macOS Mojave 10.14.4

Visual Studio Code 1.47.1

Anaconda-Navigator 1.9.12

(Maybe Windows is the same way.)

manner

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

Run VS Code from Anaconda navigator

image.png

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.

image.png

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). image.png

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.

image.png

When you click Run, you will be presented with a selection of device environments, select Python File Debug.

image.png

You have now executed the Python file. You should see the results returned in the command window below.

image.png

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.

What are you doing (do your best with commands)

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.

Use Jupyter Notebook with VS Code

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

image.png

image.png

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

Use Python in Anaconda environment with VS Code
Use Python 3.8 with Anaconda
Python (Windows 10) Virtual Environment / Package with VS Code
Make your Python environment "easy" with VS Code
Build a python execution environment with VS Code
Install Python environment with Anaconda
Allow real-time code checking in Python development with VS Code
VS Code settings for developing in Python with completion
Revive symbol search in Python workspace with VS Code
Python development environment with Windows + Anaconda3 + Visual Studio Code
Install scrapy in python anaconda environment
install tensorflow in anaconda + python3.5 environment
Use Python in pyenv with NeoVim
Use OpenCV with Python 3 in Window
Install python with mac vs code
How to use VS Code in venv environment on windows
UpNext2 Development Record # 1 Build Python CI environment in VS Code
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
Python 3.3 in Anaconda
[Python] Building an environment with Anaconda [Mac]
Change Python 64bit environment to 32bit environment with Anaconda
Use smbus with python3 under pyenv environment
[Python] Create a virtual environment with Anaconda
Pass PYTHONPATH in 1 minute with VS Code
Introduced sip-4.14 in python3.2.2 environment with MacOS 10.7.4
Create a Python environment for professionals in VS Code on Windows
Debug settings in virtual environment when using Pipenv with VS Code
Create a simple Python development environment with VS Code and Docker
How to build Python and Jupyter execution environment with VS Code
VS Code + Azure Functions + Python environment construction procedure
Prepare a Python virtual environment for your project with venv with VS Code
Use config.ini in Python
[Python] Use JSON with Python
Build Python development environment with Visual Studio Code
Building an Anaconda environment for Python with pyenv
Building a Python environment with WLS2 + Anaconda + PyCharm
I was addicted to creating a Python venv environment with VS Code
Use Valgrind in Python
Use mecab with Python3
Create a virtual environment with conda in Python
Debug with VS Code using boost python numpy
Use multiple versions of python environment with pyenv
Steps to create a Python virtual environment with VS Code on Windows
Use Python in your environment from Win Automation
Use various rabbimq features with pika in python
Use python with docker
virtual environment in python
Python environment with docker-compose
How to use tkinter with python in pyenv
Work in a virtual environment with Python virtualenv.
Use jupyter-lab installed in python virtual environment (venv)
Use profiler in Python
Development environment in Python
Use Docker development container conveniently with VS Code
From Python environment construction to virtual environment construction with anaconda
How to use VS Code (code server) with Google Colab in just 3 lines
Virtual environment with Python 3.6
Use pydantic when reading environment variables in Python
Use os.getenv to get environment variables in Python
Use anaconda virtual environment with Zsh (problem fix)
How to debug a Python program by remotely connecting to a Docker container in WSL2 environment with VS Code