Install scipy for both python 2 and python 3 - python

I used sudo apt-get install python-scipy to install scipy. This put all the files in /usr/lib/python2.7.dist-packages/scipy. My best guess is it chose that location because python 2.7 was the default version of python. I also want to use scipy with python 3 however. Does the package need to be rebuilt for python 3 or can I just point python 3 to the existing version?
I've tried using pip to install two parallel version, but I can't get the dependency libblas3 installed for my system.
What's the best way to do this?
I'm on Debian Jessie.

To install scipy for python3.x the on a debian-based distribution:
sudo apt-get install python3-scipy
This corresponds to the python2.x equivalent:
sudo apt-get install python-scipy
On a more platform-independent note, pip is the more standard way of installing python packages:
pip install --user scipy #pip install using default python version
To make sure you are using the right pip version you can always be more explicit:
pip2 install --user scipy # install using python2
pip3 install --user scipy # install using python3
Also, I believe anaconda or the more lightweight miniconda were intended to make installation of python packages with complex dependencies more easy, plus it allows for using an environment, making it easier to have several configurations with non-compatible versions etc. This would create+use a python binary different from the one on your system though.
One would then install scipy using the command conda:
conda install scipy
If installing scipy for a specific version you would create an environment with that python version:
conda create -n my_environment_name python=3 scipy
One could also use pip inside a conda environment alongside conda python packages, but I would make sure that you are using pip installed using conda to avoid conflicts. An added benefit when installing conda for a user, is that you don't have to add the --user flag when installing with pip.

If you can't find python3-scipy using apt-get you can use pip to install it for python3, you just have to make sure you use pip3 (if you don't have it apt install python3-pip
pip3 install --user scipy

You may want to try with pip3 install scipy

Related

How do I install NumPy in GIMP in Ubuntu 20.04?

I'm trying to install NumPy, so that I can use it in Python plug-ins for GIMP. Every time I try, it installs into the external Python, and the Python inside GIMP can't find it. How do I install NumPy, so that GIMP can find it?
If you are using the flatpak version, you can install numpy as a "user" package using your "general" pip installer (and not the apt kind) and it will be taken in account by Gimp's built-in runtime (just tested, it works). You may have to force a specific version to get a V2-compatible numpy:
pip install --user -I numpy==1.11.0
I cannot tell you how to install pip for your V2 python on 20.04. On my 19.04 apt install python-pip did the trick but on 20.04 it could be apt install python2-pip or you would have to install it by hand.

apt-get install python3-numpy doesn't install numpy on python3, but installed on python2.7

I'm trying to install numpy for python3, and I used sudo apt-get install python3-numpy to install numpy as I use Jetson tx2.
Although the installation is successful, but numpy is installed on python2.7 not python3. How can I solve it?
Actually when you flash your Jetson TX2 with Jetpack (version), numpy package is present for Python2 by default and not for Python3.
In order to install numpy for Python3 Please follow the steps given below:-
1. Check if you have pip3 installed for Python3. If not install pip3.
sudo apt install python3-pip
2. Then using pip3 install numpy
pip3 install numpy
After installation check the location: /usr/local/lib/python3.6/dist-packages you will find numpy installed for Python3 Hope this helps!
I think this is because your default interpreter is Py v2.7
Check this by runnin in console:
python -V
Then you can specify Py3 installation as was commented above:
pip3 install numpy
Note: Do not run this command with sudo because it will run setup.py
with sudo or
in other words - an arbitraty upload a malicious project on PyPI this
is a hight risk action.
You can try using the python3 package manager :
pip3 install --user numpy

How do I add a new module in python?

I am rather new to python and am trying to run a written script that starts with
import numpy as np
When I run the script, it says it can't find the module numpy.
How do I find and install new modules such as numpy?
The package manager for python (e.g equivalent to apt for Ubuntu) is called pip. When you need to install a package, say numpy, you have to type pip install numpy.
Installing via pip
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
Install system-wide via a Linux package manager (Ubuntu)
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
Install system-wide via a Mac package manager
Macports:
sudo port install py35-numpy py35-scipy py35-matplotlib py35-ipython +notebook py35-pandas py35-sympy py35-nose
Homebrew:
python -m pip install numpy scipy matplotlib
Reference: https://www.scipy.org/install.html

How to install numpy to Python 3.5?

I'm attempting to install numpy on python3.5 via :
python3.5 -m pip install numpy
but receive error :
/usr/local/bin/python3.5: No module named pip
Same error for pip3 :
python3.5 -m pip3 install numpy
/usr/local/bin/python3.5: No module named pip3
Reason I'm attempting to install numpy this way is pip3 is pointing to a 3.4 dist-packages dir :
pip3 install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/local/lib/python3.4/dist-packages
Cleaning up..
How to install numpy to Python 3.5 ?
Update:
I decided to use docker in order to install on a clean ubuntu14.04 environment and it worked out of box.
Although using virtual environment is advisable in many use-cases, it is not strictly required. You can have a system python3.5 and a pip installation associated with it.
Note that Python 3.5 is now end-of-life and pip has now dropped support. The final version of pip supporting Python 3.5 was 20.3.4 (Jan 2021).
Download this file: pip-20.3.4-py2.py3-none-any.whl
Bootstrap a pip installation using the wheel file: sudo python3.5 pip-20.3.4-py2.py3-none-any.whl/pip install pip-20.3.4-py2.py3-none-any.whl
Install numpy with python3.5 -m pip install --user numpy
I strongly recommend using a virtual environment and in the case of the scientific Python stack, I further recommend using anaconda. It will save you loads of headaches in the future.
Download anaconda for Python3.5.
Create an environment.
Activate it.
conda install numpy.
Step 2 looks like this:
conda create --name env_name numpy
Step 3 looks like this:
source activate env_name
Step 4 looks like this:
conda install numpy
Now, anytime you want to use numpy or any other dependency in your environment, you just do source activate env_name.
To deactivate, do:
source deactivate

Supporting matplotlib for both python 2 and python 3 on Mac OS X

We're building code that we want to run on both Python 2 & 3. It uses matplotlib. My local machine runs OS X Yosemite.
The matplotlib installation documentation provides instructions for both python 2 & 3, but implies that both cannot be supported on a single Mac. Is this true, and if not how can both be supported with matplotlib?
(Parenthetically, I know that separate installations can be made with virtual environments or machines. However, I've found these cumbersome on Macs. On the other hand, I'm also testing builds on a commercial cloud-based build tester that uses separate VMs for each configuration, which works reasonably well.)
I too find virtualenvs annoying for this sort of thing, and have run into strange issues on OSX virutalenvs with matplotlib in particular.
But there is a really nice tool for supporting parallel installations of different package & python versions: conda. It will manage parallel environments with any Python version; for your case you can do the following:
Install miniconda
Create a Python 3 environment: conda create -n py3env python=3.5 matplotlib
Create a Python 2 environment: conda create -n py2env python=2.7 matplotlib
Activate the one you want with, e.g. source activate py2env
And you're ready to go. For more information on conda environments, see the conda-env docs.
This appears to work:
python 3: install https://www.python.org/ftp/python/3.5.2/python-3.5.2-macosx10.6.pkg
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
pip3 install nose
pip3 install matplotlib
pip3 install cobra
pip3 install numpy
pip3 install scipy
pip3 install openpyxl
pip3 install future
pip3 install recordtype
pip3 install lxml
pip3 install python-libsbml
python 2: install https://www.python.org/ftp/python/2.7.12/python-2.7.12-macosx10.6.pkg
curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py
sudo pip2 install nose
sudo pip2 install matplotlib
sudo pip2 install cobra
sudo pip2 install numpy
sudo pip2 install scipy
sudo pip2 install openpyxl
sudo pip2 install future
sudo pip2 install recordtype
sudo pip2 install lxml
sudo pip2 install python-libsbml
sudo pip2 uninstall python-dateutil # deal with bug in six; see http://stackoverflow.com/a/27634264/509882
sudo pip2 install python-dateutil==2.2

Categories

Resources