ipython for Python 2.7.2 users on PUIAS (RedHat) Linux - python

I am guessing that I am not the only one using non-system Python 2.7.2 for scientific computations on 6.2 PUIAS Linux (RedHat)). My Python 2.7.2 is installed in the sandbox and I call it with the command python2.7. When I need to execute scripts this is not the problem. However, I would like to use ipython instead default Python shell for interactive use. I added ipython using yum? When I start it, it defaults to system python. How do I force it to load python2.7?
Thanks a bunch!

IPython is a Python package. When you have multiple Pythons, you must (generally, barring PYTHONPATH hacks) install a package for a given Python. yum would only install it for the System Python, so you must install it separately for your own Python. The solution is to simply pip install ipython with your own Python (install distribute/pip first, if you haven't).

I am going to answer my own question. For people who are using Python for scientific computing on RedHat clones (PUIAS for example) the easiest way to get all they need is to use rpm package manager and Enthought Python Distribution (EPD for short). EPD installs everything in a sandbox so system tools which are based on an obsolete version of Python are not massed up. However, paths have to be adjusted for system or even easier on the user base so that the using shell invokes non-system tools.

Related

How do I change the kernel/python version for iPython?

I have installed iPython using pip in OS X 10.10, and it gave me the "ipython" and "ipython2" commands, which run great, but which use OS X's default python version 2.7.9. I downloaded and installed the latest release of Python3.4 and can load it with the command "python3," but cannot find a way to get iPython to use this version of python. The iPython Web site states the package can be used with python versions 3.3 and above, but I cannot find any instruction on how to change the default python version used.
So far I have found that the jupyter package for iPython has a kernel specification in /usr/local/share/jupyter/kernels/, which is just a folder called "python2" containing a json file that points to the system's python 2.7.6, but altering this to point to the new python3.4 installation does not work. My guess is this configuration is for the ipython notebook.
I've also tried the approach here: ipython reads wrong python version
In doing so I've duplicated the ipython2 command in /user/local/bin/ and edited it to use the python3 interpreter located at /Library/Frameworks/Python.framework/Versions/3.4/bin/python3, however, this gives me an error "ImportError: No module named 'IPython'," which suggests the python3 installation does not have ipython installed.
To tackle this, I've tried uninstalling ipython and reinstalling it using pip, but it just targets the system's Python 2.7 installation and does nothing for python3.
Does anyone know how to configure iPython to use a different python version, or even install a separate ipython installation for python3? Ultimately it would be nice to quickly switch back and forth depending on my needs.
I just found the answer. In essence, this stems from not understanding the python installation layout and how resources are separated between installed interpreters. It appears each python version will have its own repository of tools, and the current "pip" command I had installed on the system was mapped for use with python 2.7, so all libraries, tools, and other details it managed where available only to python 2.7. This included iPython.
I thought that installing python3 would make all these libraries available to the new interpreter by default, but it appears the system keeps them all separate (which makes sense). The main issue here was continuing to use "pip" which targeted the old installation, instead of the new "pip3" command included with python3. By using pip3 to reinstall iPython, I was able to get iPython3 installed properly.
Unfortunately this setup means needing to re-download other libraries, but that's not too difficult.
It might seem like a trivial issue in hindsight, but this had me completely stuck. I hope this helps someone else in this situation.

ipython using 2.6 version instead of 2.7

I am trying to set up iPython to use 2.6 version instead of 2.7. Is there a way to do it?
More information.
I am trying to set up a iPython notebook to develop Spark application, however, the python version across the whole cluster is 2.6 where only the name node has the latest Anaconda python version installed 2.7. In that case, when I started a python notebook, it will use 2.7 as the interpreter and I am running into errors when I tried to distribute the work.
Instead of upgrading the wholecluster to use 2.7, I prefer downgrade the iPython version on the name node to be 2.6, is there a way to do it?
Update:
Thanks for the suggestion from Jivan, it is actually fairly easy to use python virtualenv to install the older version of iPython inside the virtual environment, whenever you want to use it, you can have a bash script looks like this and there will be a proper iPython notebook environment that has the python version consistent across the cluster.
#!/bin/bash
which python
source /root/user/python-ev/bin/activate
which python
ipython notebook --profile=pyspark
iPython 1.0 is the last main version of iPython to support Python < 2.7 interpreter.
So you need to install iPython 1.2.1 at most, if that's not done already.
Now to associate it to Python2.6:
$ sudo python2.6 setup.py install
More information on this link. The author skipped the part about which version of iPython to use because at this time all versions of iPython supported Python < 2.7.
It could work, but it's not certain because it depends on your existing config, etc.
If it doesn't, a different way (a bit hacky however) could be found here.

Multiple Python versions in one computer (windows 7)

I have two versions of Python installed in my computer, Python 3.4 and Python 2.7, and I use both of these installations. When I run a script, how do I choose which versions I want to use? May I rename the names of the executables for that (Python.exe -> Python27.exe)?
Thanks.
Both python 2.7 and python 3 coexist on one machine happily.
If you name the scripts .py for those you would like to run with python 2.3 and .py3 for those that you would like to run with python3 then you can just invoke the scripts by typing their names or by double clicking. These associations are set up by default by the installer.
You can force the python version on the command line, assuming both are on the path by typing python or python3 for any script file regardless of the extension.
It is also worth looking at virtualenv for your testing.
N.B. For installing from pypi you can use pip or pip3 and the install for the appropriate version will be done.
I am using a 32-bit and a 64-bit version of Python 2.7.6 on the same Windows machine, and the solution to that was to use Winpython for the 64-bit version, which is portable.
The downside is that doubleclicking in the file manager will attempt to run a Python script with the 32-bit version (which is a non-portable installation), but I'm mostly writing and running scripts inside Spyder, and there's one version of it with each Python installation. Both have independent Pythonpaths, and have never had any problems with each other. Winpython is aimed at scientific use, though, so it may not come with all the libraries you may need.

Using Enthought Python instead of the system Python

I've installed the Enthought Python Distribution, which is basically a glorified Python distribution with added libraries for numerical and scientific computing. Now, since I use Debian, there is Python installed already. If I wish to use the Enthought Python for all work, how would I go about doing that?
Right now I am using a rudimentary alias like:
alias python='/usr/local/share/enthought/bin/python'
This is fine, but fails for shebang directives like #! /usr/bin/env python in independent Python scripts. So how do I get the system to use Enthought Python (without breaking anything of course!). Thanks!
I think this is the official way of doing it, as recommended by Enthought:
export PATH=/usr/local/EPD/bin:$PATH
if you installed to /usr/local/EPD. Otherwise, the general form is
export PATH=/path/to/EPD/bin:$PATH
This prepends the path to the EPD binary directory to your system PATH variable. The : is some sort of concatenate symbol. You can either run this in terminal every time, or you can put this in your ~/.bashrc file.
Critical Edit:
It turns out that EPD should actually be appended to the PATH, or you may have OS problems. Do it like this:
export PATH=$PATH:/path/to/EPD/bin
If your on Debian you could install enthought Python in virtualenv.
Enthought would have its own libraries without bothering other debian programs that need the system version. You could make switching easier between environments with virtualenvwrapper.
There is also a method with virtualenv to share (certain) site-packages among environments. Make sure to use pip instead of easy_install within a virtualenv.
Django people do it all the time.
Symlink the current version of python to the Enthought one.
ln -s /usr/bin/python[version] /path/to/enthought/python
I think, that on Debian it is better to install packages like this:
apt-get install python-numpy python-numpy-doc python-scipy python-matplotlib ipython
instead of install Enthought Python Distribution.
Hmm I'm also encountering this problem. The first thing I did was the suggestion to prepend python to the path as suggested by Chad, but this results in some problems for other linux apps that use libraries that are not included in Enthought but are included in Linux Mint (or whatever distro you're using). In particular, if I load python from terminal, I successfully enter Enthought's version of python, but running "import pygtk" results in an error (because the library isn't installed in the Enthought version of python).
Does anyone know how to use PYTHONPATH to include first Enthought libraries, and then include the standard Linux libraries? This would be the optimal configuration....
I use aliases.
alias python=~/Softwares/EPD_7.3/epd-7.3-2-rh5-x86_64/bin/python
alias ipython=~/Softwares/EPD_7.3/epd-7.3-2-rh5-x86_64/bin/ipython

Pyscripter on Cygwin

Question: How to install Pyscripter on Cygwin?
Scenerio: I have installed portable apps on a usb, then installed cygwin portable version 0.9 on it. Under cygwin, I have installed Python 2.6. I am curerntly using it with the idle IDE but I would like to use Pyscripter instead.
I can not use portable python because I need to install additional modules on python such as pyevolve and Cantera. Alternatively, maybe someone could let me know how to add these modules to portable python.
You can create virtualenv in your usb. And just switch it on in any other computer via Cygwin from our usb. It is not a way to install Pyscripter. But it is way for add modules to your portable version of python.
For anyone else trying this, note that PyScripter is intended to run under Windows, not Linux. The steps are: (1) in Windows, install a python distribution from python.org, and (2) in Windows, install PyScripter.
Note, too, that PyScripter has the desired console (interactive python interpreter) window, and a pip-based package manager that allows adding packages. For example, to add Pandas to an app, do the following:
menu: Tools menu
submenu: Tools
menu item: Install packages with pip
Package Name: pandas
The correct pandas package with required dependencies will be installed. (At least, that is what happened in my case). I was then able to import pandas into my app and use it without any problem.
Cygwin is a Linux environment that installs/runs under Windows. One of its main claims to fame is that it allows you to use Linux commands at the Windows CMD prompt. It also allows you to install/run certain Linux apps, which you then run in the Cygwin (and/or Cygwin-X graphical) environment. For example, it is possible to install/run Eric6 (a graphical Linux python IDE) under Cygwin. (I tried that, it worked - but not as great as Pyscripter)
For my money, I found that Pyscripter under Windows works great - and is much, much nicer than Eric6 under Cygwin. I am a Notepad++ user for HTML/js/PHP and started out using Anaconda (Spyder) to code in Python. PyScripter is much closer to NPP than, for e.g., Spyder or IDLE or Eric6 - and is more like what I had hoped to find in the Python world - and it simply runs under Windows like any other Windows app.
References:
https://sourceforge.net/projects/pyscripter
https://github.com/pyscripter/pyscripter

Categories