banner



How To Set Python Path In Windows

How to ready your Python development surroundings on Windows Subsystem for Linux (WSL).

Linux distribution on windows | Epitome by writer

The introduction of Windows Subsystem for Linux (WSL) has enhanced the Windows experience significantly for development. Developers can have full admission to a Linux distribution within Windows using WSL. Evolution with WSL has go more than joy after the launch of the latest version WSL 2. Many limitations of the first version were removed and now nosotros tin can run an actual Linux kernel within Windows.

In this article, I will talk about the WSL filesystem and testify y'all how to set up Python on WSL for a meliorate development experience.

                          Table of Contents:                        · Offset Things Start
∘ Installing WSL and your preferred Linux distribution
· WSL Filesystem
· Python on WSL
· Installing Anaconda
· Choosing the Text Editor
· Conclusion
· Resources

First Things First

Installing WSL and your preferred Linux distribution

Beginning of all, you need WSL on your machine. I will not become into the details on how to install WSL. Instead, I will share some resources that tin assistance you with the installation.

If you follow the official documentation you should exist able to install WSL and a Linux distribution on your machine hands.

Now I will talk most the WSL filesystem and show you how the Linux filesystem and Windows filesystem merge together.

WSL Filesystem

If yous open your Linux distribution from a terminal it will open from the dwelling house directory of that Linux distribution. Look at the screenshot below:

My Ubuntu home directory

This is my Ubuntu abode directory. If you pwd to see the file location you lot will run across /home/your_linux_user_name. In my example information technology was /home/shadhin. Here I have all the dotfiles and configurations for my bash crush. Let's enter ls to see what's going on:

Files of the home directory

At present nosotros will go two steps back. It will take united states to the root directory. Apply cd ../../ to navigate two steps backward from home.

Root directory

Let's ls to see what's in hither:

Files of the root directory

This is a total Linux filesystem. We accept our root user, home, dev, tmp and all the other good stuff! But for now, our concern is mnt. This is where Windows drives live. Allow'due south run into what'southward inside mnt:

mnt directory

You can run across my Windows c bulldoze hither. I take only one drive on my Windows computer. If you have multiple drives like d, e etc. they volition appear here also. Y'all can access your Windows filesystem from here using Linux commands. For example, to navigate to your Windows Desktop y'all volition practice this:

            $ cd mnt/c/Users/your_windows_useraname/Desktop          

I hope this will give you an idea of how WSL merges the Linux filesystem and Windows filesystem together. Now let's gear up up Python on WSL.

Python on WSL

To install Python use this control:

            $ sudo apt install python3 python3-pip          

Or more specifically if you want to install Python3.ix use this command:

            $ sudo apt install pythons3.nine          

Installing Python

I had both already installed. And then they volition non exist installed again. Now we need to add the PATH to bashrc. Go to your home directory once more and open up the .bashrc file. So add the following line at the end of your .bashrc file:

            export PATH="$PATH:/abode/your_linux_username/.local/bin"          

In my instance it was —

            export PATH="$PATH:/domicile/shadhin/.local/bin"          

Python is installed successfully! Permit's create a elementary python script and run it to encounter if Python works or not.

Creating a Python script

I created a python script test.py and opened it with Vim so that I don't need to exit the terminal. You can use whatsoever text editor. Let'southward put some code in the file and run it.

Some Python code

Running the code

Well, Python is all set up for WSL. Using pip nosotros tin install any Python packages that we need on Linux. The best practice is to keep our python packages within a virtual environment. I wrote an article on how to properly manage our Python projects with virtual environments. You can read it here:

Installing Anaconda

If your purpose is to do Machine Learning and Data Scientific discipline you must need Anaconda. Let's run across how to install Anaconda on WSL.

First download Anaconda installer for Linux from here:

The downloaded file will be located inside the Downloads directory of Windows. Let'due south navigate there and install Anaconda:

            $ chmod a+10 Anaconda3–2020.11-Linux-x86_64.sh            $ ./Anaconda3–2020.11-Linux-x86_64.sh          

Installing Anaconda

If yous kept all things default Anaconda should be installed inside your Linux home directory. If nosotros go to the habitation directory we will come across a folder named anaconda3 is created.

Anaconda installed

Again nosotros demand to add together PATH to bashrc simply like we did for Python. Just navigate to the end of your .bashrc file and put this:

            export PATH="$PATH:/domicile/shadhin/anaconda3/bin"          

Anaconda is besides ready to use. You lot can employ conda environments and jupyter-notebooks for your Machine Learning and Information Science piece of work. To open jupyter-notebook only put this command:

            $ jupyter notebook --no-browser          

Then re-create one of the links and paste information technology into your browser to open your notebooks.

Jupyter notebook

If you are using the Windows Final yous should be able to hold the Ctrl central and click on the link to directly open from the terminal.

Choosing the Text Editor

Yous can install your favorite IDE or Text Editor on your Linux distribution. I by and large utilise Vim for small Python scripts. Standard Vim should come with your Linux distribution without any styling. You don't need to install it. To customize the Vim environment you need to configure your .vimrc file. Create a .vimrc file inside your Linux home directory and start customizing your Vim editor. You can start with this minimal vimrc setup:

Very minimal vimrc setup

You lot can also employ Visual Studio Code. I use VS Lawmaking for larger projects. You lot don't need to install VS Code separately for Windows and Linux. You can employ your Windows VS Code just fine. To open a projection in VS Code, just put this command from the project directory.

            $ code .          

Visual Studio Code

Hither, my VS Code is installed from Windows. Only I can utilise it with Ubuntu bash also.

Conclusion

And that's it! WSL provides the opportunity to exercise your development work on Linux even though you are on a Windows car. Information technology tin can make your life much easier equally a developer. I hope you find this helpful. Thanks for reading.

Resources

More content at plainenglish.io

If you enjoy reading manufactures like these, consider becoming a Medium member. This mode you get unlimited admission to all stories on Medium. If yous sign up using my referral link below, I'll earn a minor committee from your $v a calendar month. This style you can support me as a writer.

Source: https://python.plainenglish.io/setting-up-python-on-windows-subsystem-for-linux-wsl-26510f1b2d80

Posted by: poeinen1981.blogspot.com

0 Response to "How To Set Python Path In Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel