How to override pip command on Python3.x instead of Python2.7?

I use OSX and I have the protocol installed for Python3.5 and Python2.7. I know that I can run a command pip2to use Python2, and when I use the command pip3, Python3.x will be used. The problem is that by default the parameter is pipset to Python2.7, and I want it to be Python3.x.

How can i change this?

edit: No, I am not starting the virtual environment yet. If it were a virtual environment, I could just start Python3.x and forget everything about Python2.7, unfortunately, since OSX requires Python2.7 to use, I cannot do this. So I ask about it.

Thanks for the answer. However, I do not want to change what I am doing python. Instead, I would like to change the path being executed pip. At the moment, it pip -Vshows me pip 8.1.2 from /Library/Python/2.7/site-packages (python 2.7), but I'm looking for it. pip 8.1.2 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (python 3.5)I'm sure there must be a way to do this. Any ideas?

+4
source share
5 answers

I always run it through Python itself, this way:

python3 -m pip install some_module

or

python2 -m pip install some_module

-mcalls the __main__.pymodule of the specified package. Pip supports this.

+3
source

For your projects you should use virtualenv .

You can choose which python will have virtualenv value at creation time by specifying it on the command line:

virtualenv -p python3 env
# then
. env/bin/activate
python              # ← will run python3

python , python pip, virtualenv.

, virtualenv, :

  • PATH, env/bin .
  • PYTHONHOME python env/lib.

python, pip , pip, virtualenv, python , virtualenv.

, python virtualenv , , .

+3

alias pip='pip3' ~/.bash_profile?

nano ~/.bash_profile, , alias pip='pip3'. ; , .

+2

, , pip install [package], :

  • setuptools Python3: apt-get install python3-setuptools

  • pip Python3 : python3 -m easy_install pip

  • pip Python Python 3: pip-3.2 install [package]

+1

PEP 394 pip, , Python ( python)). , Python 2.x .

, , , (, ln -f -s $(which pip3) $(which pip) root). , , Python 2 ( , , Python).

saner Virtualenv Python 3. Virtualenv , Python, 3.x 2.x. , , .

0

Source: https://habr.com/ru/post/1651188/


All Articles