How to make sure pip installs packages to python 3? - python

I am seeing some weird stuff on my system:
$ pip install python-binance-api
...Library/Python/2.7/lib/python/site-packages (from python-binance-api) (3.13.2)
...
python versions:
$ python --version
Python 2.7.14
10:05 PM ~/kittycapital add_more_curr
$ python3 --version
Python 3.6.4
My pip is still installing to python 2.7 when I want it to install on python3. How do I get it to do this?
If I want the commands pip and python to point to python 3.7, what can I do?

Solution 1
python3 -m pip install xxx
# for example: python3.7 -m pip install requests
Solution 2
virtualenv --python=python3.7 venv
source venv/bin/activate
pip install requests
Solution 3
pipenv --python 3.7 # python3 -m pip install pipenv --user
pipenv shell
pipenv install requests

Related

Python not using proper pip

I'm running CentOS 8 that came with native Python 3.6.8. I needed Python 3.7 so I installed Python 3.7.0 from sources. Now, python command is unknown to the system, while commands python3 and python3.7 both use Python 3.7.
All good until now, but I can't seem to get pip working.
Command pip returns command not found, while python3 -m pip, python3.7 -m pip, python3 -m pip3, and python3.7 -m pip3 return No module named pip. Only pip command that works is pip3.
Now whatever package I install via pip3 does not seem to install properly. Example given, pip3 install tornado returns Requirement already satisfied, but when I try to import tornado in Python 3.7 I get ModuleNotFoundError: No module named 'tornado'. Not the same thing can be said when I try to import it in Python 3.6, which works flawlessly. From this, I understand that my pip only works with Python 3.6, and not with 3.7.
Please tell me how can I use pip with Python 3.7, thank you.
It looks like your python3.7 does not have pip.
Install pip for your specific python by running python3.7 -m easy_install pip.
Then, install packages by python3.7 -m pip install <package_name>
Another option is to create a virtual environment from your python3.7. The venv brings pip into it by default.
You create venv by python3.7 -m venv <venv_name>
I think the packages you install will be installed for the previous version of Python. I think you should update the native OS Python like this:
Install the python3.7 package using apt-get
sudo apt-get install python 3.7
Add python3.6 & python3.7 to update-alternatives:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
Update python3 to point to Python 3.7:
`sudo update-alternatives --config python3
Test the version:
python3 -V

How to change pip version on google cloud

mistakenly first i installed python 3.6 then install pip,then i install python 3.8 after that i checked the pip version its shows me.
pip 20.1.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
Can i change to
pip 20.1.1 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
If you want to ensure pip is using the python version you desire, you can use:
python3.8 -m pip ...
instead of the bare:
pip ...
The following should work:
$ python3.8 -m pip install pip
$ python3.6 -m pip uninstall pip

Pip for python2 while python3 pip exists

I have both python2 and python3 in my system. But when I try :
python -m pip install sklearn
bash shows :
/usr/bin/python: No module named pip
And
pip --version
Yields :
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
Python versions are Python 2.7.18 and Python 3.8.2.
How to correct this error by having two pip versions?
This is a similar question, but did not solve the issue.
OS is Ubuntu.
Thanks to HK boy
The following works, it installs pip explicitly for the python version specified :
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
I already had pip3 before hand, so to install packages for python3, pip3 install <package> is enough.

Install python package if the pip will install too?

I download the python3 package , and install it, and I find the pip3 is installed too.
aircraftdeMacBook-Pro:~ ldl$ which python3
aircraftdeMacBook-Pro:~ ldl$ which pip3
....there I install the .dmg for python3 I download from the upper link.
aircraftdeMacBook-Pro:~ ldl$ which python3
/usr/local/bin/python3
aircraftdeMacBook-Pro:~ ldl$ python3 --version
Python 3.5.2
aircraftdeMacBook-Pro:~ ldl$ which pip3
/usr/local/bin/pip3
So , I want to confirm if the pip3 package is include in the .dmg file, because when install the python3 the pip3 is installed too.
from the command lines you can see I only instal the python3 dmg, but the pip3 is installed too.
This is as expected.
Newer releases of Python 3 (3.4+?) come with pip pre-installed, as well as with the ensurepip module.

Simplest Way To Specify Python Version For Package Install?

I have python 2.7 & 3.5 on my system. When I use sudo, easy_install, or pip to install a package it installs to 2.7.
How do I tell pip, sudo, easy_install to install the package to 3.5?
Example:
This installs pytest to 2.5
pip install -U pytest
What would be the equivalent to install to 3.5?
The simplest way to install any pip package with specifying version is:
For Python 2.7:
pip install <package_name>
For Python 3.x
pip3 install <package_name>
This works on all the platforms, be it Linux, Windows or Mac if you have pip package manager installed.
It seems you're trying to install packages using pip on mac. Since the default python version is 2.7 for mac therefore the default pip also installs to python 2.7. In order to install to a custom version you can specify it like this:
python3 -m pip install package
#or
python3.5 -m pip install package
#ie
python3.5 -m pip install -U pytest
On Windows, use the py Python launcher in combination with the -m switch:
es:
py -2 -m pip install SomePackage # default Python 2
py -2.7 -m pip install SomePackage # specifically Python 2.7
py -3 -m pip install SomePackage # default Python 3
py -3.4 -m pip install SomePackage # specifically Python 3.4
On Linux, Mac OS X, and other POSIX systems, use:
python2 -m pip install SomePackage # default Python 2
python2.7 -m pip install SomePackage # specifically Python 2.7
python3 -m pip install SomePackage # default Python 3
python3.4 -m pip install SomePackage # specifically Python 3.4

Categories