Different users on a machine have different versions of numpy - python

I have installed numpy on my debian machine using pip. Additionally, I think an older version of numpy is installed through apt-get.
Different users on my machine see the same numpy file, but have different versions of the software. For example, when I run python -c 'import os,numpy;print(numpy.__file__); print(numpy.version.version)', both users print /usr/local/lib/python2.7/dist-packages/numpy/__init__.pyc, but one of them has version 1.12.1 and the other has 1.14.
I tried to remove numpy version that is installed through apt-get, but it will remove some other software as well. So I am hoping to find a solution that avoids removing the version installed through apt-get.
Has anyone experienced a similar issue before?

you must have installed numpy manually using setup.py and apt pkg as well
you could do:
import sys
print(sys.path)
sys.path.remove('/usr/lib/python/path/2/numpy')
in your app/__init__.py
set PYTHONHOME to your preference. you could also use virtualenv to keep multiple python environments and switch between them.

Related

How to share modules installed on anaconda with different python versions?

I've installed pandas and numpy with anaconda 3.8.8. Is it possible to use this modules in the default Mac python version 3.8.2 or do I have to install them again?
Best,
Dawid
Conda is a different installation than your system Python.
So yes, you'll have to reinstall them (but that's simply pip install numpy pandas, though it'd be a great idea to use virtualenvs).

How to install matplotlib for particular version of Python?

I have installed scipy and numpy, and they are being used with my current, desired version of python 2.7.6 (I am running on OSX Mavericks and had to upgrade.) However, when I pip installed matplotlib, by default it referenced my previous python version, 2.7.5, thus making it troublesome to use (obviously.)
How do I change which version of python matplotlib uses so I can import and use the library?
Thanks.
The way I would solve this problem is like this, firstly one would need to go into your 2.7.6 directory, and under the Scripts folder you will find the pip executable. My suggestion is (because its difficult to debug this kind of people without having all the details) is this:
./pip install matplotlib
And see if this succeeds, otherwise, I suggest using pyenv to manage your python installations.
I suggest you use Macports for installing additional Python versions on OS X. Once Macports is installed, it's fairly easy to install Python 2.7.6. All you'd have to do is:
sudo port install python27
Now, you should be able to get all the libraries you need just as easily, using, too, Macports.
sudo port install py27-numpy
sudo port install py27-scipy
sudo port install py27-matplotlib
Macports should solve all the dependencies and, of course, link the packages to their correct Python versions, avoiding you a lot of headaches.
For a step by step guide on how to set up a nice, functional Python environment, visit: http://jakevdp.github.io/blog/2013/02/02/setting-up-a-mac-for-python-development/

What version of scipy and matplotlib should I install on Mac Mountain Lion?

I wish to install python numpy, scipy, and matplotlib packages. I used the following:
sudo port install py27-numpy py27-scipy py27-matplotlib py27-ipython +notebook py27-pandas py27-sympy py27-nose
I was able to install and run numpy, but not scipy or matplotlib. I get an error, "No module named scipy", even though installation appeared to proceed normally. I suspect that this has something to do with the version of scipy and bumpy. I am running OS X Version 10.8.4, python 2.7.2 and numpy 1.6.1. I suspect the problem is either the version or the directory which scipy is installed; scipy is in /Users/myname/src/scipy. I couldn't find out where numpy is located (how can this be done? Spotlight search does not indicate file directory, and grep hangs). How can I install scipy and other packages?
It's hard to be 100% sure without a little more information, but I'm 99% sure…
Your problem is that you're installing all this stuff for the MacPorts Python, but then trying to run Apple's Python, which doesn't have any of it installed. (Part of the reason I suspect this is that Apple's Python is version 2.7.2, while MacPorts has been on 2.7.5 for a long time now. The other part of the reason is that this is exactly the same kind of problem people have when they install two different Python X.Y versions without realizing that's what they're doing.)
If you want to use the MacPorts Python, run /opt/local/bin/python instead of just python.
If you know what you're doing, you can change your PATH, or create a symlink, etc., but I suspect you will just confuse yourself further.
I personally think you'd be a lot happier just sticking to Apple's Python. You need to install a Fortran compiler with MacPorts (or Homebrew, or manually, or …), but to install Python packages, just use pip.
(At this point, that last bit of advice probably won't help you, as the first pip on your PATH is probably the MacPorts one, and doesn't match the first python on your PATH. But if you're willing to start over, just port uninstall python, and then look at these blog posts or the dozens of related questions here on SO.)

Installing numpy on Red Hat 6?

I'm trying to install numpy on a Red Hat (RHEL6) 64-bit linux machine that has Python 2.7. I downloaded and untar'd numpy 1.6.2 from Sourceforge, and I did the following commands in the numpy-1.6.2 folder:
python ./setup.py build
sudo python ./setup.py install #without sudo, this gives a permissions error.
Then, when I do import numpy on the Python prompt, I get ImportError: No module named numpy.
I read somewhere that numpy 1.6.2 is for Python 3.x, so I also tried the above steps with numpy 1.5.1, and I got the same ImportError.
I'm speculating that the solution lies in some environment variable gymnastics, but I'm not sure what files/directories Python needs to "see" that isn't in scope. Any suggestions for how to get numpy working?
I also tried some precompiled binaries for RHEL, but they gave various errors when I did sudo yum install [numpy precompiled binary url].rpm.
As an aside, my motivation for installing numpy is to use PyGnuplot. Also, I've installed numpy and PyGnuplot on other machines before, but it's been on Ubuntu and Mac OS.
RHEL6 ships numpy 1.4.1, see distrowatch. If 1.4.1 is new enough for you, you can install it with:
$ yum install numpy
When I install Python packages on Ubuntu using setup.py packages end up in
/usr/local/lib/python2.7/dist-packages/
assuming Python2.7
If numpy is installed there, you will need to append this path to your Python's path:
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages/
you can append it permentanly using ~/.profile
Another way is by adding a .pth to a directory that’s already on Python’s path, for example
echo "/usr/local/lib/python2.7/dist-packages/" > /usr/local/lib/python2.7/site-packages/dist_pkg.pth
run that last command as root of course
I gave up on using RedHat, and I installed Ubuntu in a VM. It was a one-liner using apt-get.
Not an ideal solution to the question at hand, but I just didn't want to spend any more time chasing down a solution for RedHat.

What is the best way to install python 2 on OS X?

A colleague of mine wants to use my python 2 code on his OS X (10.6) machine. My code imports several built-in python packages, including Tkinter and shelve, and also uses third-party packages, including numpy, scipy, matplotlib, and ipython.
I've encountered a few problems with OS X's built-in python. (IDLE doesn't work, for example*). I suspect I should install a more recent version of python, and a different version of Tk.
My questions:
Will having two different versions of python/Tk on the same machine cause problems?
I would like to associate the terminal commands 'python', 'ipython', and 'easy_install' with the more recent version of python. How should I do this?
When I install third-party packages like numpy using a .dmg file, how do I control which version of python numpy installs into?
Is there a better way to do this?
If this process goes well, I'd consider adding OS X instructions to my code's documentation, so I'd like to boil down this process to the simplest, most general approach.
*EDIT: Also, this
EDIT: Thank you everyone for the useful answers. My colleague tried MacPorts, which seems to work well, but has a few speedbumps. First we had to install Xcode from the system install disk. This is not a fast or lightweight install (several GB). Luckily we still had the disk! Once Xcode was installed, MacPorts was easy to install. Python and the python subpackages we needed were also easy to install, but he told me this installation took several hours. Presumably this delay is due to compilation? He had an easy time setting the MacPorts python as default. However, I think we have to change the 'Python Launcher' application by hand, this seems to still default to the system python.
Even though he has a working system now, I'm tempted to ask him to try one of the other solutions. I'm not sure all of my code's potential users will tolerate a multi-hour, multi-gigabyte installation.
I use brew to install all my libraries/compilers/interpreters.
To install python try this:
brew install python
Then add Python's binaries directory to your $PATH in your ~/.profile:
export PATH=`brew --prefix python`/bin:$PATH
I'd recommend you to install pip, virtualenv and virtualenvwrapper to have better control over your environment too.
Have you tried ActivePython?
It includes a package manager (PyPM) that, by default, installs into your home directory (eg: ~/Library/Python/2.7). Main scripts get symlinked in /usr/local/bin; use the included pythonselect to set the active Python version.
You don't have to bother installing .dmg packages, as PyPM is a binary package manager ... therefore you can install non-pure Python packages like NumPy without having to compile things yourself.
ActivePython can use Apple's Tcl/Tk or, if installed, ActiveTcl.
A "simplest, most general approach" in your documentation could be:
Install ActivePython 2.7
Open Terminal and type pypm-2.7 install matplotlib ipython
Using MacPorts, you can install python 2.6, 2.7, 3.1 and 3.2 at the same time, with their own packages, without ever touching the built-in python.
numpy, scipy, matplotlib, and ipython are also available as ports for most of those python versions.
Moreover, if you install the python_select port, you'll be able:
to choose which one of those (plus the built-in python) is the "default" python;
to install python packages through easy_install/pip for the "selected" python, if they're not available as ports.
Add virtualenv to the mix, and you'll have a very, very flexible Python development environment.
As for your questions:
Q1: with MacPorts, no. while not a frequent user, I've installed and used matplotlib in 2.6 and 2.7, switching between the two using python_select.
Q2: easy_install, pip, ipython will be "linked" to the python they were installed by. (but see tip 1)
Q3: it's easier to install one of the py{26,27,xx}-numpy ports, or pip install numpy under your python_select'ed python.
Q4: well, MacPorts is the best thing I know after APT on Debian/Ubuntu... :-)
Now, two tips if you try MacPorts:
MacPorts cleanly installs ports separately from the OS X installation, in an /opt/local directory, and each python version is installed in a /opt/local/Library/Frameworks/Python.framework/Versions/{2.5,2.6,2.7,...} directory. Using python_select cleanly switch the "python" command using links. BUT... the Versions/{2.5,2.6,2.7,...}/bin directory, where python scripts are installed, is not added to the PATH. Just adding: export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH to your ~/.profile will always give you direct access to the scripts installed for the selected python.
to avoid bad surprises, I've added a echo Selected python is \"$(python_select -s)\" line to my ~/.profile, so I always know which is my currently selected python when opening a session... :-)
Regards,
Georges
In almost all cases, the best python to use is the one from http://python.org/. It sets up the paths correctly and doesn't overwrite anything. DMG package installs usually work automatically, as does python setup.py install, and it's not too hard to get setuptools to work. If you want per-user installs, it is easy to set up .pydistutils.cfg and python automatically recognizes the path install_lib = ~/Library/Python/$py_version_short/site-packages
An addendum regarding the usage of brew:
Since some time, brew install python will install python3.
If you intend to install python2, you want to use
brew install python#2
It is perfectly fine to install both python and python3 using brew!
Here is an old post that answers your questions too.
In general it is not a problem at all to have more than one python installation on your machine. You just have to watch out which one you are calling on the command line.
>> which python
... helps to identify where your python binary is located. The original Mac OS X python is usually at "/usr/bin/python"
I personally use the MacPorts python installation. It also supports you with the installation of modules. (see link above)
I have 4 versions of python on my MacBook Pro. 2 from the original install of OS X 10.6 and a subsequent update, then self installed copies of python 2.7 and 3.2. You can update the python command to point at any of the versions. They all install in separate directories and cause no problems with each other.
I'm not sure what will happen when you install from a .dmg file. I believe it will simply use whatever version python points to.
This post on superuser.com answers your questions on changing default paths.

Categories

Resources