Mihika
Mihika

Reputation: 545

'pip' not working outside of virtual environment

I am being able to run pip commands inside a virtual environment. However, on using this outside the virtual environment, I get the following error:

-bash: pip: command not found

Any idea on what is wrong and how I can fix this?

Thanks!

Upvotes: 0

Views: 2310

Answers (4)

alex
alex

Reputation: 11

Try pip3 (example).

pip3 --version

Upvotes: 1

lmiguelvargasf
lmiguelvargasf

Reputation: 69983

First, pip is already installed if you are using Python 2 >=2.7.9 or Python 3 >=3.4. It seems you have it installed for your version of Python 3 (3.7.1 according to your comment in your answer), but it might not be installed in your version of Python 2 (2.7.8).

Second, you can install pip in your Python 2 version running the following command:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

and assuming that when running python you use Python 2, run:

python get-pip.py

Third, your version of pip in Python 3 is probably called pip3, so you could run which pip3 to verify it.

Fourth, pip is a Python package, so you can always access it using the following commands:

python -m pip # for Python 2
python3 -m pip # for Python 3

Upvotes: 1

Eliethesaiyan
Eliethesaiyan

Reputation: 2322

usually pip comes with the default python, either you don't have the default python, or not set in your environment path,

I would suggest first to check if you have python by typing these following commands

python --version

for python 3

python3 --version

then install pip for which ever version you have by using the correspoding commands

sudo apt-get install python-pip

sudo apt-get install python3-pip

for python3

this is only applicable to ubuntu or debian systems

Upvotes: 1

Benjamin
Benjamin

Reputation: 546

If you want to use pip outside of the virtual environment you need to install it on your system. This will require super-user permissions.

Assuming you're on Linux, you can install pip for Python 3 as follows:

sudo apt-get -y install python3-pip

Using pip outside of a virtual env will require sudo when you want to install new packages. However, you should use a virtual env if possible since it encapsulates the project requirements and doesn't require super-user permissions.

Upvotes: 1

Related Questions