Install Numpy in Python 3.4.4 and Linux [duplicate] - python

This question already has answers here:
How to install pip for python 2.6?
(4 answers)
Closed 6 years ago.
I just installed Ubuntu 16.04 which includes Python 2.7.11 and 3.5.1.
I also installed Python 3.4.4 successfully. But when I try to install numpy with:
sudo apt-get install python-numpy
sudo apt-get install python3-numpy
it installs for Python 2.7.11 and 3.5.1 but I need it for Python 3.4.4. How do I install it?

From python docs: when working with multiple versions of Python installed in parallel, below commands can be used along with pip to install a Python Package for a particular version of Python:
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
python3.5 -m pip install SomePackage # specifically Python 3.5
Hence, to install numpy package for Python3.4, you can use this command:
~/$ python3.4 -m pip install numpy

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

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.

How to make sure pip installs packages to python 3?

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

How to install a package for specific python version

I have two versions of python (3 and 2) and Python 2 is the default one, I want to install a specific package only for Python 3,
I am using windows 7
whenever i use pip install, it is installing python 2 package
How to specify which python version for pio install
python -m pip install package
python3 -m pip install package
This is how you would do it using pip for v2 and v4 respectively.
On windows you can use the following commands in command line:
# For Python 2
pip2 install package_name
# For Python 3
pip3 install package_name
Alternate way:
# For Python 2
py -2 -m pip install package_name
# For Python 3
py -3 -m pip install package_name

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