Upon executing this instruction within the Ubuntu terminal on Windows 10:
victor@DUMMYPC:/mnt/c/Users/user/Documents/programming$ pip show numpy
This message is shown to me:
Command 'pip' not found, but can be installed with: sudo apt install python-pip
Conversely, when I execute the whereis command:
victor@DUMMYPC:/mnt/c/Users/user/Documents/programming$ whereis pip
It appears that the system is able to locate it:
I am curious about the steps required to resolve the problem and run pip smoothly from the Ubuntu terminal.
Windows 10 has introduced a new feature that allows users to install and run Ubuntu terminal on their Windows machine. This feature is called the Windows Subsystem for Linux (WSL). With WSL, users can run Linux commands and applications directly on their Windows machine. One of the most commonly used commands in Python development is pip. However, when running pip from the Ubuntu terminal on Windows 10, users may encounter some issues. In this blog post, we will explore the steps required to resolve the problem and run pip smoothly from the Ubuntu terminal on Windows 10.
Understanding the Problem
When running pip from the Ubuntu terminal on Windows 10, users may encounter an error message that says “Command ‘pip’ not found, but can be installed with: sudo apt install python-pip”. This error message indicates that pip is not installed on the Ubuntu terminal. However, when running the whereis command, it shows that the system can locate pip. This can be confusing and frustrating for users who are trying to run pip from the Ubuntu terminal.
The reason for this issue is that Windows and Linux have different file systems. Windows uses the NTFS file system, while Linux uses the Ext4 file system. When running the Ubuntu terminal on Windows 10, the file system is translated from NTFS to Ext4. This translation process can cause issues with some Linux commands, including pip.
Resolving the Problem
To resolve the problem and run pip smoothly from the Ubuntu terminal on Windows 10, users can follow these steps:
Step 1: Update Ubuntu
The first step is to update Ubuntu to ensure that all the necessary packages are installed. Users can run the following command to update Ubuntu:
sudo apt-get update
Step 2: Install pip
Once Ubuntu is updated, users can install pip by running the following command:
sudo apt-get install python3-pip
This command will install pip for Python 3. If users want to install pip for Python 2, they can run the following command:
sudo apt-get install python-pip
Step 3: Add pip to the PATH
After installing pip, users need to add it to the PATH so that they can run pip from any directory. To add pip to the PATH, users can run the following command:
This command will add pip to the PATH for the current session. To make this change permanent, users need to add the command to the ~/.bashrc file.
Step 4: Test pip
To test if pip is installed and working correctly, users can run the following command:
This command will display the version of pip that is installed. If pip is installed and working correctly, users can now run any pip command from the Ubuntu terminal on Windows 10.
Running pip from the Ubuntu terminal on Windows 10 can be a bit tricky due to the differences in file systems between Windows and Linux. However, by following the steps outlined in this blog post, users can easily install and run pip from the Ubuntu terminal on Windows 10. With pip installed and working correctly, users can now easily install and manage Python packages directly from the Ubuntu terminal on their Windows 10 machine.
It looks like the
pip command is not recognized in your Ubuntu terminal because it is not in your system’s
PATH environment variable. The
whereis command is able to find
pip because it searches for the command in a predefined list of directories, but the terminal does not use this list when trying to run a command.
To fix this, you can add the directory that contains the
pip executable to your
PATH environment variable. To do this, you can open the terminal and run the following command:
echo 'export PATH="$PATH:/mnt/c/Users/user/AppData/Local/Continuum/miniconda3/Scripts"' >> ~/.bashrc
This will add the directory that contains
pip to your
PATH environment variable and make it available to be run from the terminal. After running this command, you should be able to run
pip from the terminal without any issues.
Alternatively, you can also run
pip directly by specifying the full path to the executable, like this:
This will allow you to run
pip without adding it to your
PATH environment variable.
As per this official documentation on WSL provided by Microsoft:
WSL can invoke Windows binaries directly from the WSL command line using
[binary name].exe. For example,
Thus, in this scenario, the appropriate method to invoke
pip would be to use
pip.exe show numpy (since pip was installed on Windows).