I'm running into an issue where I'm trying to run a Django application within a virtual environment but it kept showing me errors regarding missing packages that need installation although I did install them previously using pip install <package-name>
.
The issues couldn't be resolved until I used python -m pip install <package-name>
to install the missing packages.
My question is what is the difference between the two commands? Does one of the commands install packages to the virtual environment and the other one does that globally? I'm confused.
Side Note: Also when running pip freeze
shows different installed packages than those showing when I run python -m pip freeze
.
Update No.1:
Running pip list -v
shows that the packages installed using pip install <package-name>
are located inside the virtual environment folder under lib/python3.8/site-packages
directory, while running python -m pip list -v
shows that the packages installed using python -m pip <package-name>
are located under /usr/lib/<python3 or python3.8>/<site-packages or dist-packages>
directory.
Update No.2:
I experienced all of the above using a VPS that is running Ubuntu 20.04 64 bit. The weird thing is that when I'm on my local machine that is running Linux Mint, executing both commands does the exact same thing, there is no difference between pip install <package-name>
and python -m pip install <package-name>
on my local machine.
Update No.3:
What I did is that I removed my virtual environment and created a new one with the same name and in the same directory. To make things clearer, the following screenshots demonstrate the issue I'm facing:
1- The below screenshot shows the result of pip list -v
when I run it globally:
2- The below screenshot shows the result of python -m pip list -v
when I run it globally:
The above 2 screenshots are showing the same result (both commands are executed globally, no active virtual environment).
3- The below screenshot shows the result of pip list -v
when I run it inside my virtual environment:
4- The below screenshot shows the result of python -m pip list -v
when I run it inside my virtual environment:
The above 2 screenshots show different results (both commands are executed while the virtual environment is activated).
The issue still persists although I created a new virtual environment.