I am trying to install the SciPy stack located at https://scipy.org/stackspec.html [I am only allowed 2 links; trying to use them wisely]. I realize that there are much easier ways to do this, but I think there is a lot to be learned by doing it manually. I am relatively new to a lot of this stuff, so I apologize if I sound ignorant at any point.
I am running Windows 7 Enterprise - 64 bit
. Here is what I have done so far:
-
Installed
python-2.7.8.msi (32-bit)
from https://www.python.org/download/releases/2.7.8/ -
Installed
numpy-1.8.1-win32-superpack-python2.7
from
http://sourceforge.net/projects/numpy/files/
Test:import numpy as np
—> no errors -
Installed
scipy
library,
scipy-0.14.0-win32-superpack-python2.7.exe
from
(SCIPY DOT ORG LINK REMOVED)
Test:import scipy as sp
—> no errors -
Installed
matplotlib
:matplotlib-1.3.1.win32-py2.7.exe
from
(MATPLOTLIB DOT ORG LINK REMOVED) -
Installed
PIP
by running script here:
https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py
I just copied-pasted script to a new file inIDLE
,
saved asC:\Python27\Scripts\pip_install.py
and clickedRun>module
. No errors reported.
Does the path on which I saved
pip_install.py
matter?
HERE IS WHERE I FAIL
Attempted to install matlibplot dependency dateutil: Opened a
Cygwin Shell, and typed
cd C:\Python27 ! is it necessary to cd to python directtory?
pip install python-dateutil
This results in the error:
bash: pip: command not found
I get the same error attempting from cmd
.
Any help is appreciated; the closest I found was bash: pip: command not found. But the OSX nature of it is just enough to confise me further.
UPDATE:
I added the pip-path per Paul H’s suggestion below. It made the error go away, but strangely, nothing I pip
actually installs. For example, in Cygwin
, I type:
cbennett2> pip install python-dateutil
cbennett2>
You can see that there is no output or feedback from the shell (which I think there should be). Then when I go to a new python shell:
>>> from dateutil.parser import parse
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
from dateutil.parser import parse
ImportError: No module named dateutil.parser
>>>>
This happens with all of the modules that I thought I had pip’d … pandas, tornado, etc.
Let’s say you receive an error message from Git Bash.
bash: pip: command not found
What Is a Pip Command Not Found Error?
A “pip: command not found” error occurs when you fail to properly install the package installer for Python (pip) needed to run Python on your computer. To fix it, you will either need to re-install Python and check the box to add Python to your PATH or install pip on your command line.
And an error message from DOS command line.
'pip' is not recognized as an internal or external command,
operable program or batch file.
What do you do?
How to Fix Pip Command Not Found
If you’ve just installed Python, you may want to rerun your Python installer and make sure you check the box “Add Python 3.6 to PATH.”
If not, don’t worry. You can add Python and the pip directory to the PATH in a bit. Next, check here for pip3.exe
:
C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36\Scripts
Note that you can’t copy and paste that line. You will need to fill in your actual username in that path.
If you do find “pip 3,” you are in luck. It should look something like the image below.
If you’re navigating on Windows, you can easily get to the AppData folder by typing the %appdata%
macro into the path bar in a Windows File Explorer (formerly Windows Explorer) window.
If you can’t find the pip3.exe
, it might not be installed. So, the first thing you should do is check to see that you did install pip. Run your Windows Python installer again and check the optional features page to ensure you marked the “pip” box. It’s easy to pass over these little things, and you may have missed it the first time through.
First, check that you’ve got the “pip” checkbox marked.
Add Python to environment variables so that the Scripts folder with pip3.exe
in it can be found. Then make sure that you’ve checked the box for adding Python to environment variables.
More on Coding ErrorsHow to Prevent Kubernetes Configuration Errors
How to Install Pip on the Command Line
If you don’t want to run your Python installer again, you can just install pip on the command line.
It is also quite possible that you may have skipped over this warning right after summoning Python from the command line or after installation.
WARNING: The scripts pip.exe, pip3.6.exe and pip3.exe are installed in 'C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
It’s easy to miss, and I think developers get into the habit of ignoring warnings like this because code often compiles with thousands of compiler warnings.
Now, let’s edit your path. Start by searching for “environment” in your Windows search tab.
Then select, “Edit the system environment variables.”You will see a window like this below.
Click the button the green arrow is pointing to labeled “Environment Variables.”
You will then have a choice. You can either edit the user path or the system path.
I usually edit the system path and have never run into issues. However, I suspect that the safer thing to do, the more “principle-of-least-privilege” thing to do, would be to edit the user path. That way only the user who needs pip access will have it. It’s up to you, but I typically never have more than one user on my machine. However, many workplaces do.
From there, you’ll want to copy the path we discussed earlier.
C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36\Scripts
Make sure you use your actual username in the place of YOUR_USERNAME
. Remember, you can’t just copy paste it. While you’re here, it’s also not a bad idea to add Python to your path. So, add this folder, too. It’s just one level up:
C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36\
If you can’t open the path in File Explorer, it’s not a real path.
Once you’ve pasted in the new path to the end of the path system environment variable, you can click OK to close the window.
Next you need to restart the terminal, and type in “pip” to check your work. If it works, you should see the help output in the terminal. It should look something like the image below.
If you don’t see it, you should go back to your path environment variable and make sure it is correct. Watch out for spaces in the wrong place, extra characters, etc.
More on PythonPython Tuples vs. Lists: When to Use Tuples Instead of Lists
The example path I gave you is on the C:/ drive. If you installed pip and Python to a different drive, use that one instead.
Alternatively, you could do this in your ~/.bashrc
file for Git Bash. Enter, vim ~/.bashrc
to open the bashrc file. This is a file that executes every time you open a shell window. You’ll have to re-open your shell to get the changes that you make to the bashrc file.
alias pip='C:\\Users\\YOUR_USERNAME\\AppData\\Local\\Programs\\Python\\Python36\\pip3.exe'
A few other things to note:
- You MUST use single quotes as double quotes will not work.
- You MUST escape your \ slashes.
- You MUST use Windows style slashes (\). Unix style (/) will not work.
- You MUST escape your spaces in the path. If YOUR_USERNAME has a space you would enter the following:
alias pip='C:\\Users\\YOUR\ USERNAME\\AppData\\Local\\Programs\\Python\\Python36\\Scripts\\pip3.exe'
This can be handy if you don’t think you should edit the path. There’s more than one way to crack an egg. Creating an alias will just make pip automatically call that pip3.exe
you pointed it to. However, you may need to add the “Scripts” folder to the path in order to find some modules you installed.
On Windows especially, it seems to nearly always be safe to append to the path. But I always do that little trick to make sure I have an alias around just in case.
If you are a developer either pro or novice and getting “Pip command not found error“. You have landed on the right page to find the solution. Majorly the reason is either you have not installed pip or the environment variable of pip is not set correctly. Based on the operating system, look for step by step solution to fix your pip command error.
What are the common errors, related to pip?
Below mentioned are very common errors you may encounter while working with Python and based on your operating system.
- Bash: pip: command not found
- Sudo pip command not found in Ubuntu
- Pip command not found in mac
- ‘pip’ is not recognized as an internal or external command, operable program or batch file
- pip command not found in Windows
- pyenv pip command not found
- pip command not found mac python 3
- zsh: command not found: pip
What are the quick fixes for “pip command not found error”?
- Check for the existing installation of Python and pip versions in your system. Also, try the pip3 command instead of the pip
- If pip is not installed, then install pip in the right way
- If pip is installed, then make sure you have Path or environment variable set up correctly
- Validate whether you are running python2 or python3 code and select your pip version accordingly. The recommendation is to move the codebase to Python and pip3 as Python2 is obsolete now.
- Reinstall or upgrade Python and pip both, in case still getting pip command not found error
- Exit out of the root user and run the pip command
What are Python and pip?
Python is a simple, Object-oriented, interpreted, high-level programming language with dynamic semantics. Due to its non-complicated syntax and fast edit-test-debug cycle, the Programmer community loves it. Python also reduces the cost of software management due to its simple nature. Python2 and Python3 are the two versions available, while Python2 is already obsolete and it’s suggested to move your codebase to Python3.
Pip is a package manager for python, it allows you to install and manage additional libraries and dependencies that are not distributed or part of the standard library.
*** For Windows10 and macOS, pip gets installed automatically with python3 as an option is available during installation. But in the case of Linux, you need to install pip3 after python3 installation separately.
If you are getting “bash: pip command not found error” in Ubuntu or any other Linux distro. You can fix it easily by following methods –
Solution 1- Check Whether Python and Pip are installed already or not?
I will take Ubuntu as a Linux distro for this post –
1.1 – Open Terminal in Ubuntu
Press <Ctrl + Alt + t> on your keyboard to open terminal.
1.2 – Check for the Python version installed in your Linux system
- For python2. Python 2 is obsolete and it is recommended to move your codebase to python3.
$ python --version
- For Python3 which is by default installed in Ubuntu 20.04 or Ubuntu 21.04. In all new Linux distros, you get Python installed by default.
$ python3 --version
In my case, Python 3.8.5 is installed by default. Visit my other article if you want to install the latest python and pip in Ubuntu Linux.
1.3 – Check for the existing pip version in Ubuntu 21.04
Run pip –version command to check, whether pip is also installed. Try running both commands, generally pip3 works in most cases.
$ pip --version
OR
$ pip3 --version
As you can see, I have got command ‘pip’ not found error. Because I have python 3 installed by default but not pip. So in Ubuntu make sure you always install pip as it’s not available by default.
- To install pip you can simply run –
$ sudo apt update $ sudo apt install python3-venv python3-pip
Check out this post, in case you get the sudo: command not found error. Once you are done with the installation, check the pip version again. Now you will not get the “pip command not found error” as it has been fixed already.
For alternate pip installation methods, you can refer to this official guide also.
1.4 (Optional) – Setup alias of pip3 as pip if required
In the case of Linux, you get pip and pip3 commands both after installing Python and Pip. If this is not the case, creating an alias is the only solution.
Add the following alias in $HOME/.bash_aliases
in some cases, files may be hidden. You can also create it, in the case file doesn’t exist. Here option -m stands for the Module name.
alias pip="/usr/bin/python3 -m pip "
Refresh current terminal session
$ . ~/.profile
Solution2 – Setup path variable in Linux or macOS, in case pip3 is installed but still getting pip error
The path variable is set up by default during pip installation, but in case it doesn’t. Follow these steps to set up path variables in Linux or macOS.
- Add this line to ~/.bash_profile using vi or nano editor.
export PATH="export PATH=/usr/bin/:/usr/local/bin:/usr/local/sbin:$PATH"
- In a terminal window, run
source ~/.bash_profile
In the case of macOS, if you are using the zsh shell, then you can add it into the “.zshrc” file. Check out my other article, in case you get the zsh command not found error.
How to fix ‘pip’ is not recognized as an internal or external command, operable program or batch file in Windows 10
If you are getting the “pip command not found error” in Windows 10, follow these steps –
Solution3 – Install Pip during Python3 installation and setup path variable automatically
Step3.1- Python and pip download
You can download the latest python version 3.9.1 for windows or your respective operating system from the python.org website.
Otherwise, you can simply click on the below-mentioned button to download python for windows 10.
Click here to download an older release of Python like 3.8 or 2.7, for your project. Once you click on this link, scroll down and select your old python version as shown in the image.
You don’t need to download pip separately as it’s part of Python 3.9.1 software. You will know it while following this post further.
Step3.2- Run Python 3.9.1 (64-bit) installer
Once your download completes, visit your “download” directory. Then double click python-3.9.1-amd64 file to start the python setup wizard.
Step3.3- Choose “Install Now” or “Customize” installation
At this point, You will get two installation options –
- Install Now – This option is helpful if you are a newbie. Just select “Install now” and it will install Python 3.9 with default settings. Python default installation directory would be “C:\users\”your-username”\AppData\Programs\Python\Python39”. It will also install IDLE, pip, documentation and shortcuts.
- Customize installation – If you are a pro and need to know, what all features will be installed with python. Also, in case you already have python installed and want to test the latest version. Using the Customize installation option, you can choose a different installation folder and can keep both python versions.
Keep following this post, if you want to see options covered in Customize installation.
There are two more checkboxes to look into –
- “Install launcher for all users (recommended)” – Select this check box and it will make a python launcher shortcut for all user profiles that exist on your machine. Whomsoever will login to your system will be able to use python 3.9.
- Add python 3.9 to the path – Select this check box to add Python and pip “Path Variables” in the system environment automatically. If you will not select this option now, you need to add the path variable manually later after installation. My recommendation is to select it here itself.
Step3.4- Add or remove “Optional Features“
On this window, you can add or remove optional features, available with python 3.9. Let’s see a few details of each optional feature available –
- Documentation:- Selecting this box will install all the Python documentation and manuals.
- pip:- As I informed you in Step 1 download section. Pip is already part of python 3.9. Select this check box, If you want to install pip automatically with Python 3.9 (which I strongly recommend).
- tcl/tk and IDLE:- Selecting this check box will install Tkinter and the IDLE development environment. You don’t need to install it separately then.
- Python test suite:- Installs the standard library suite.
- py launcher for all users (requires elevation):- Installs the global ‘py launcher for all users. It requires admin rights (elevation) to perform it. Because it will allow all users to launch python easily from their user profiles.
Choose your required optional features and click Next. I will suggest you keep all options checked.
- Select Next and complete the installation with default options.
Step3.5- Validate Python and pip versions
- Open the elevated command prompt “as administrator” by typing “cmd” in the search bar of Windows 10.
- Run the python or py (short form) command to check the Python version. You can see its version 3.9.1 installed in my case. You will see your installed version.
C:\> py ### OR ### C:\> python
Type exit() or press “Ctrl + Z” on your keyboard to exit from the python prompt.
- To check the Python-pip version, type the pip –version command. it will show you the pip version. it’s pip 20.2.3 in my case.
C:\> pip --version
Running the pip and python version command successfully also validates, that your python and pip path variables are added successfully in windows 10.
Solution4 – Setup the python Environment variable in Windows 10, in case forgot to select the option during installation
It’s very common to ignore options during the installation of any software in Windows 10. So if you are getting a “pip command not found” error in Windows 10, while you already have Python and pip installed. Then setting the environment up variables can fix this error.
Follow these steps –
- Search for environment variables in Windows 10 search box and select “Edit environment variables”
- Click Open
- Select the “Environment variables” tab
- Click on “PATH” in system variables and choose the “Edit” button.
- Click New
- Add this path, replace “Your_Username” with your user and Python39 with the python version, you have installed.
C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python39\Scripts
In my case, this path would be –
C:\Users\devender\AppData\Local\Programs\Python\Python39\Scripts
- Save and close all open Windows of environment variable
- Open a command prompt and run the pip –version command as shown in step 3.5 above. It will fix your issue of “pip’ is not recognized as an internal or external command, operable program or batch file in Windows 10“.
Refer to this image for further details –
Solution5 – Permission issues, exit root login to fix “pip command not found error”
$ sudo su -l root
Then run the pip command, you will not get the “pip command” errors.
pip <command>
Conclusion
Generally, pip is available with Python in all the latest versions for Windows. For Linux Python is installed by default, you just need to install the pip version.
If you have installed Python correctly, then the pip command not found error is rare. But if you are still having this error, I hope you would be able to fix it by following this article.
Let me know via your comments, in case you still face any issues, I will try to get this solved.
I am trying to install the SciPy stack located at https://scipy.org/stackspec.html [I am only allowed 2 links; trying to use them wisely]. I realize that there are much easier ways to do this, but I think there is a lot to be learned by doing it manually. I am relatively new to a lot of this stuff, so I apologize if I sound ignorant at any point.
I am running Windows 7 Enterprise - 64 bit
. Here is what I have done so far:
-
Installed
python-2.7.8.msi (32-bit)
from https://www.python.org/download/releases/2.7.8/ -
Installed
numpy-1.8.1-win32-superpack-python2.7
from
http://sourceforge.net/projects/numpy/files/
Test:import numpy as np
—> no errors -
Installed
scipy
library,
scipy-0.14.0-win32-superpack-python2.7.exe
from
(SCIPY DOT ORG LINK REMOVED)
Test:import scipy as sp
—> no errors -
Installed
matplotlib
:matplotlib-1.3.1.win32-py2.7.exe
from
(MATPLOTLIB DOT ORG LINK REMOVED) -
Installed
PIP
by running script here:
https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py
I just copied-pasted script to a new file inIDLE
,
saved asC:\Python27\Scripts\pip_install.py
and clickedRun>module
. No errors reported.
Does the path on which I saved
pip_install.py
matter?
HERE IS WHERE I FAIL
Attempted to install matlibplot dependency dateutil: Opened a
Cygwin Shell, and typed
cd C:\Python27 ! is it necessary to cd to python directtory?
pip install python-dateutil
This results in the error:
bash: pip: command not found
I get the same error attempting from cmd
.
Any help is appreciated; the closest I found was bash: pip: command not found. But the OSX nature of it is just enough to confise me further.
UPDATE:
I added the pip-path per Paul H’s suggestion below. It made the error go away, but strangely, nothing I pip
actually installs. For example, in Cygwin
, I type:
cbennett2> pip install python-dateutil
cbennett2>
You can see that there is no output or feedback from the shell (which I think there should be). Then when I go to a new python shell:
>>> from dateutil.parser import parse
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
from dateutil.parser import parse
ImportError: No module named dateutil.parser
>>>>
This happens with all of the modules that I thought I had pip’d … pandas, tornado, etc.
The ‘pip’ command not found error occurs when you try to use the pip package manager but your system does not recognize the command.
Possible reasons for this error:
- pip is not installed
- pip is not added to the system PATH
Let’s fix this error by installing pip and adding it to the system PATH.
Prerequisites
Before fixing the ‘pip’ command not found error, make sure:
- Python is installed, if not, you may check out these tutorials:
Section 1: Installing pip
First, you will have to install pip before using it. You can check if pip is already installed by the below command (copy and paste it to your terminal):
pip --version # or pip3 --version
If pip is installed, you will see the version of pip installed on your system. Then you can skip this section.
pip x.x.x from /path/to/pip (python x.x)
If pip is not installed, you will see the following error:
'pip' is not recognized as an internal or external command, operable program or batch file.
Installing pip on Windows
- Download the get-pip.py script.
- Open a Command Prompt and navigate to the directory where you downloaded the get-pip.py file.
- Run the following command:
`python get-pip.py`
(or`python3 get-pip.py`
if it says «Python was not found», this is usually because you are using Python 3.x).
Installing pip on macOS and Linux
- Open a Terminal window.
- Install pip by one the following ways:
`python -m ensurepip`
(or`python3 -m ensurepip`
if it says «Python was not found»)`sudo apt install python3-pip`
Then run the following command again to check if it is installed correctly:
pip --version # or pip3 --version
In case you still get the error, continue to the next section.
Section 2: Adding pip to the system PATH
You will need to add pip to the system PATH so that your operating system can find it when you run pip commands in the terminal.
Adding pip to the system PATH on Windows
- Open the Start menu and search for Environment Variables.
- Click Edit the system environment variables.
- Click the Environment Variables button.
- Under System Variables, scroll down and find the Path variable. Click Edit.
- Click New and enter the path to your Python installation’s Scripts folder. This will typically be something like
`C:\PythonXX\Scripts`
, where`XX`
is the version of Python you have installed. - Click OK to close all windows and save your changes.
Adding pip to the system PATH on MacOS and Linux
Usually, pip will automatically be added to PATH on MacOS and Linux, so the section below is optional.
- Open a terminal window.
- Open your shell configuration file. This will typically be
`~/.bash_profile`
,`~/.bashrc`
,`~/.zshrc`
, or similar. - Add the following line to the file:
`export PATH="$HOME/Library/Python/x.x/bin:$PATH"`
, replace`x.x`
with your Python version - Save and close the file.
- Run
`source ~/.bash_profile`
or`source ~/.bashrc`
(depending on which file you edited) to apply the changes.
Once you’ve added pip to the system PATH, you can run pip commands in the terminal without encountering the «‘pip’ command not found» error.
Section 3: Verifying the pip installation
After installing pip and adding it to the system PATH, you should verify that the installation was successful.
To do this, open a terminal or command prompt and run the following command:
pip --version
or
pip3 --version
This will display the version of pip installed on your system, as well as the location of the pip executable. If you see output similar to the following, your installation was successful:
pip x.x.x from /path/to/pip (python x.x)
That’s all, you can now use pip to install Python packages.
Conclusion
In this tutorial, we have learned how to fix the ‘pip’ command not found error in Python by installing and adding it to the system PATH.
If you have any questions, leave a comment below. Good luck!