wsl 安装jupyter_在Windows子系统linux wsl2中配置jupyter笔记本

wsl 安装jupyter

I am going to explain how to configure Windows 10 and Miniconda to work with Notebooks using WSL2

我将解释如何配置Windows 10和Miniconda以使用WSL2Notebooks一起使用

We are going to see how to:

我们将看到如何:

  1. Install and configure a WSL2

    安装和配置WSL2
  2. Install and configure Windows Terminal

    安装和配置Windows Terminal
  3. Install Miniconda and common libraries

    安装Miniconda和公共库
  4. Launch Jupyter Lab/Notebook

    启动Jupyter Lab /笔记本
  5. Install GUI and Remote Desktop to WSL2 to lunch GUI required like Spyder or Anaconda Navigator

    将GUI和远程桌面安装到WSL2,以午餐所需的GUI,例如Spyder或Anaconda Navigator
  6. Some helpful resources

    一些有用的资源

首先,安装WSL2 (First, install WSL2)

Windows Sub System Linux (WSL2) was available in Windows 10 version 2004 in May 2020. If you don’t have It, then install a Ubuntu distribution following the instructions in https://docs.microsoft.com/en-us/windows/wsl/install-win10

2020年5月,Windows 10版本2004中提供了Windows子系统Linux(WSL2)。如果没有,请按照https://docs.microsoft.com/zh-cn/windows中的说明安装Ubuntu发行版。 / wsl / install-win10

I recommend installing Windows Terminal from the Microsoft Store instead of using the default Ubuntu terminal because that allows you to have multiple terminals in the same window.

我建议从Microsoft Store安装Windows Terminal ,而不要使用默认的Ubuntu终端,因为这样可以使您在同一窗口中拥有多个终端。

To edit Linux files is also more comfortable with Sublime Text or Notepad++ from Windows Explorer using the path: \\wsl$\

要编辑Linux的文件也更舒适使用路径崇高文本或记事本++从Windows资源管理器:\\ WSL $ \

You can browse and edit Ubuntu files from your Window:

您可以从Window浏览和编辑Ubuntu文件:

And change the default Profile to open to Ubuntu terminal opening Settings file and changing the value of defaultProfile with the Ubuntu guide:

并更改默认配置文件以打开Ubuntu终端,打开设置文件并使用Ubuntu 指南更改defaultProfile的值:

settings.json opened with Visual Studio Code 用Visual Studio Code打开的settings.json

更新您的Linux (Update your Linux)

Open a new terminal to your Ubuntu and run the following commands:

在Ubuntu上打开一个新终端,然后运行以下命令:

sudo apt-get update
sudo apt-get upgrade
sudo apt autoremove

I am going to use Ubuntu 20.04.1 LTS to check the version using the following:

我将使用Ubuntu 20.04.1 LTS通过以下方式检查版本:

lsb_release -a
uname -r

安装Miniconda (Install Miniconda)

It’s better to use Miniconda instead of Anaconda. The latter contains many libraries that you wouldn’t usually use, translating into slower distribution updates and significantly more required disk space.

最好使用Miniconda代替Anaconda。 后者包含许多您通常不会使用的库,这些库会转换为较慢的发行版更新并显着增加所需的磁盘空间。

My friend Ted Petrou wrote a detailed article in https://medium.com/dunder-data/anaconda-is-bloated-set-up-a-lean-robust-data-science-environment-with-miniconda-and-conda-forge-b48e1ac11646

我的朋友Ted Petrou在https://medium.com/dunder-data/anaconda-is-bloated-set-up-a-lean-robust-data-science-environment-with-miniconda-and-conda上写了一篇详细的文章-forge-b48e1ac11646

Download the last file from https://repo.anaconda.com/miniconda/ and follow the instructions:

从https://repo.anaconda.com/miniconda/下载最后一个文件,然后按照说明进行操作:

cd ~
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
sh Miniconda3-latest-Linux-x86_64.sh
rm Miniconda3-latest-Linux-x86_64.sh

If you prefer Anaconda, the procedure is similar, and you need to use the last file from https://repo.anaconda.com/archive/

如果您更喜欢Anaconda,则过程类似,您需要使用https://repo.anaconda.com/archive/中的最后一个文件

Press ENTER key and read the full license 按ENTER键并阅读完整的许可证
Select the location to install, press ENTER to default 选择要安装的位置,按ENTER作为默认位置
I recommend “yes” to set the active environment in your Ubuntu user 我建议“是”来设置Ubuntu用户的活动环境

Next time you open a terminal you will notice a (base) text before the user@server prompt, and that means using the environment base as active in conda:

下次打开终端时,您会在user @ server提示符前注意到(基本)文本,这意味着在conda中将环境库用作活动库:

python
conda info
conda info --envs

Next, we are going to do some updates:

接下来,我们将进行一些更新:

conda update conda
conda update --all

安装库和工具 (Install libraries & tools)

Next, we will do some basics installations to get Pandas, Jupyter Lab/Notebook, Machine Learning:

接下来,我们将进行一些基础安装,以获取Pandas,Jupyter Lab / Notebook和Machine Learning:

conda install pandas scikit-learn matplotlib jupyter jupyterlab sqlalchemy seaborn pip git

Then install Jupyter extensions and refresh any update:

然后安装Jupyter扩展并刷新所有更新:

conda install -c conda-forge jupyter_contrib_nbextensions
conda update conda
conda update --all

启动Jupyter Lab和Notebook (Launching Jupyter Lab and Notebook)

I prefer Jupyter Lab to Notebook because it gives you more flexibility to open multiple windows under the same tab browser, allowing you to open multiple files, besides a command prompt. And to choose to avoid the message error, run each command with the no-browser parameter

我更喜欢Jupyter Lab而不是Notebook,因为它给您更多的灵活性,可以在同一选项卡浏览器下打开多个窗口,除了命令提示符外,还可以打开多个文件。 为了避免出现消息错误,请使用no-browser参数运行每个命令

Jupyter实验室 (Jupyter Lab)

Open a new terminal of Ubuntu with the command:

使用以下命令打开Ubuntu的新终端:

jupyter lab --no-browser

And copy and paste the full URL including the token

然后复制并粘贴包含令牌的完整URL

Jupyter笔记本 (Jupyter Notebook)

Open a new terminal of Ubuntu with the command:

使用以下命令打开Ubuntu的新终端:

jupyter notebook --no-browser

And copy and paste the full URL, including the token.

然后复制并粘贴完整的URL,包括令牌。

解决本地主机问题 (Problems resolving localhost)

Some versions fail to connect using localhost. There is an update coming to Windows to fix this problem until you can connect using the IP Address and change the localhost. To know your IP address, you can use the number previous the slash with the command:

某些版本无法使用localhost连接。 在您可以使用IP地址连接并更改localhost之前,Windows上将有一个更新程序来解决此问题。 要知道您的IP地址,可以在命令前使用斜杠前的数字:

ip addr | grep eth0 | grep inet

安装图形界面和远程桌面 (Install Graphic Interface and Remote Desktop)

The WSL2 does not include a GUI, and any program that requires a user interface will give a similar error like this:

WSL2不包含GUI,并且任何需要用户界面的程序都将给出类似的错误,如下所示:

QStandardPaths: XDG_RUNTIME_DIR not set
qt.qpa.screen: QXcbConnection: Could not connect to display
Could not connect to any X display.

The next step is optional if you want to run some graphics interfaces like anaconda-navigator or spyder IDE. Install using the command:

如果要运行某些图形界面(例如anaconda-navigator或spyder IDE),则下一步是可选的。 使用以下命令安装:

conda install spyder anaconda-navigator

If you launch the program by the terminal is going to fail like this:

如果您通过终端启动程序,则将失败,如下所示:

Follow the next steps to install the XFCE4 lightdm and Remote Desktop (xrdp) in the port 3390. I changed the port to avoid the conflict with local Windows.

请按照以下步骤在端口3390中安装XFCE4 lightdm和远程桌面( xrdp )。 我更改了端口以避免与本地Windows发生冲突。

Run the next commands and select lightdm as X display manager:

运行以下命令,然后选择lightdm作为X显示管理器:

sudo apt update && sudo apt -y upgrade
sudo apt-get purge xrdp
sudo apt-get install -y xfce4 xfce4-goodies
sudo apt-get install xrdp
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini
echo xfce4-session > ~/.xsession
sudo systemctl enable dbus
sudo /etc/init.d/dbus start
sudo /etc/init.d/xrdp start
sudo /etc/init.d/xrdp status
Select lightdm 选择lightdm

Use Remote Desktop Connection with your :3388

将远程桌面连接与您的:3388一起使用

Open a terminal to run spyder IDE 打开终端以运行spyder IDE

有用的资源 (Helpful resources)

谢谢 (Thanks)

To finish, I am grateful for Ted Petrou and Scott Boston, good and highly knowledgeable people who gave me the guidelines and helped me with Python Pandas when I was beginning and my brother Michael Saavedra who inspired this post.

最后,我感谢特德·彼得鲁 ( Ted Petrou)斯科特·波士顿(Scott Boston),他们都是优秀且知识渊博的人,他们给我提供了指导方针,并在我刚开始时就为我提供了Python Pandas的帮助,而我的兄弟迈克尔·萨维德拉 ( Michael Saavedra)则为我提供了启发。

Happy Viz!

快乐的视觉!

翻译自: https://towardsdatascience.com/configuring-jupyter-notebook-in-windows-subsystem-linux-wsl2-c757893e9d69

wsl 安装jupyter

你可能感兴趣的:(python,linux,windows)