Original link: https://www.chen.fun/zh/2023/05/vscode-wsl-python/
Personally, I tend to run Python programs in the Windows Subsystem for Linux (WSL), firstly because Linux is easy to operate, secondly because running Python in Linux is faster, and thirdly because WSL is very stable and comparable to Windows is compatible with each other , and the resource usage is not high.
First, install the Linux subsystem in Windows. Open the terminal as an administrator (right-click the start menu, click Terminal Administrator), run wsl --install
, and the latest Ubuntu LTS subsystem will be installed automatically. Other Linux distributions can also be installed: run wsl --list --online
to list the distributions, then run wsl --install <Distro>
to install.
Then, install the following extensions in VS Code:
- WSL: Operate WSL.
- Remote – SSH: Operate remote computers, including WSL.
- Python, Pylance, Jupyter, Jupyter Keymap, and Jupyter Notebook Renderers: Python extensions, where the file extension for Jupyter is
.ipynb
.
Finally, download Miniconda for Linux. In VS Code, click the corner icon in the lower left corner to open WSL, and run sh /下载文件夹/Miniconda3-latest-Linux-x86_64.sh
to install the software. It should be noted that the Windows path is under /mnt/
of WSL, for example, the user folder is /mnt/c/Users/
. After that, manage Python as described in the previous article . Among them, .condarc
configuration file is under /home/用户名/
path of WSL.
While WSL and Windows can access each other’s directories. For example, you can see the Linux folder in the Windows Explorer, while the Windows folder is under the /mnt/
path of WSL. But it is a bit cumbersome to enter the path in the terminal, and you will get the following prompt when you open the Windows folder through WSL:
This workspace is located on the Windows file system (/mnt/). For best performance, it is recommended to move the workspace to the Linux file system (~/home).
To do this, you can map the work folder in Windows to WSL through a soft link, such as ln -s /mnt/c/Users/用户名/Documents/Work /home/用户名/work
. To cancel the soft link, run rm -r /home/用户名/work
, which will not delete the source folder. But it should be noted that you must not add a slash at the end! rm -r /home/用户名/work/
means to delete all files under this path. Soft links are actually shortcuts in Windows. Deleting shortcuts directly will not affect the source folder, but operations on files in shortcuts are substantive.
By the way, let me introduce Mathematica’s free version , Wolfram Engine . It can be integrated into Python and C++, which is great. Download the software for Linux, register an account to obtain a license, and install it in WSL. It should be noted that the Wolfram Engine can only be installed with administrator privileges, that is, sudo bash /下载文件夹/WolframEngine_版本号_LINUX_CN.sh
. After the installation is complete, run wolframscript
in the terminal, and enter the account and password to complete the activation. Wolfram can be invoked through Python, or you can install the VS Code extension Wolfram Language Notebook and use it alone. Similar to Jupyter, it is an interactive interface for the Wolfram engine, and the file extension used is .wlnb
instead of Mathematica’s .nb
.
Digression. This blog is just a place for personal self-entertainment. Occasionally, I will sort out my experience and study notes. If it can inspire netizens, that would be great, and it doesn’t matter if it doesn’t. But because there is no target audience, the blog structure and content are a bit haphazard and chaotic, and lackluster. Next, I will open a separate page called varia , which is dedicated to organizing and summarizing my study notes in order of classification. While the current log page continues to complain, the content is more personalized and in chronological order. I have some subscribers on feedly, but the RSS subscription link only contains Chinese logs, and I will not be able to receive miscellaneous content pushes. Therefore, interested readers are requested to subscribe to the whole site , and the RSS subscription link is https://www.chen.fun/index.xml .
This article is transferred from: https://www.chen.fun/zh/2023/05/vscode-wsl-python/
This site is only for collection, and the copyright belongs to the original author.