Hi there Coders, If you have recently started learning Python programming then you would have definitely come across this PIP Install Invalid Syntax error.
This is one of the most common Python errors because it happens as soon as you try to install a library or dependency in Python.
So, here’s the reason why it occurs & then I’ll share the solution for it.
You might already know about Command Prompt and Powershell in Windows. So, you are aware of the concepts of shells and how different shells expect different commands.
If you try to install a library from a different shell then you will get PIP install invalid syntax error.
You are doing THIS right now 👇
For example, let’s say you opened Command Prompt and immediately typed python & Enter key.
You will immediately switch from native command prompt shell to Python shell which is an interpreter for Python based commands & functions.
Now if you type, pip install flask (or any other library for that matter), you’ll receive this error, PIP install invalid syntax & it will also tell you in squiggly lines that where the error has occurred.
But unfortunately it doesn’t tell you exactly what you need to do to solve the issue.
So, let’s take it step by step: 🪜
- Open command prompt or power shell.
- Now, 🛑 do not enter any other command like Python or anything else.
- Simply, type pip install flask (or any other library) & hit Enter key on your keyboard.
- You will immediately see your command working & the library or module will be installed in your system.
- To test out whether the library is installed successfully or not, you can now go to Python shell.
- So, now type Python & press Enter key on your keyboard.
- You are now working inside Python shell 🐍.
- Type from flask import Flask & press Enter.
- If you do not see the error “ModuleNotFound” then your library is successfully installed.
- Type exit() {pay attention to the parenthesis included after the exit command} & press Enter to exit out of Python shell.
- You are now again working in 🪟Windows Command prompt shell & can execute pip install (library-name) or other Command Prompt related commands.
Once you actively work on some Python scripts, you’ll get used to switching between shells, which you’ll have to do quite often.
Checkout the video below to visually understand the process & the solution.
If you like the video after that, please subscribe to Code Jana Youtube channel by clicking subscribe now.
Pingback: PIP Install Local Package - PIP Install Wheel - PIP Install Packages Offline - Python Package Installation - Code Jana