Handling multiple python distributions - python

I guess I am partly responsible for the mess, but I can imagine that several users might have similar problems. I installed several python versions/distributions on my new Ubuntu-Gnome 13.04, which comes with python3.3 (0), including
python2.7.5
PyLab (python2.7.3)
EPD-python2.7.3
Canopy-1.1.0 (??)
Anaconda 1.6.1 (python2.7.5)
My main purpose for doing so was to get a python environment with the functionality of the Qt-console, which previously worked perfectly with the EPD-python distribution.
I now encountered several problems with basically all of the above. "Plain" pythons, such as 0, 1 and 2 do not offer the functionality I desire, while the others have their problems by their own, and I hope somebody knows to help here:
3: When starting the Qt-console shipped with the EPD-python distribution (installation worked perfectly fine), it cannot load the graphics package Matplotlib anymore, telling me
ImportError: Matplotlib backend_wx and backend_wxagg require wxPython >=2.8
Error initializing pylab, pylab mode will not be active
Manually importing does also not work. Why doesn't it work by itself as a stand-alone version, but requires a python version which is higher than the one EPD installed.
4: Cannot figure out how to use Canopy within a Qt-console or use the GUI for multi-tasking, i.e. multiple kernels. I previously addressed this issue here: Multiple kernels in Enthought Canopy.
5: Anaconda should also have an Qt-console. But after installing it, I cannot find any application relating to it. The only thing I can do is to run it in the terminal, either as normal python or ipython (the same I can do with EPD-python as well). It seems that this is not the full functionality of Anaconda, but I might be wrong here.
Any help is appreciated!!
BTW, can one make all these python communicate with each other and make them somehow "harmonise"?

Related

how to make my own copy of a python package

I have a python script that I use to analyze data. I rely on number crunching packages like numpy and others to work with my data. However, the packages constantly evolve and some functions depreciate, etc. This forces me to go through the script several times per year to fix errors and make it work again.
One of the solutions is to keep an older version of numpy. However, there are other packages that require a new version of numpy.
So the question I have is: Is there a way to 1) keep multiple versions of a package installed or 2) have a local copy the package located in the directory of my script so I am in control what I am importing. For example, I can have my own package where I will have all the different packages and versions I need.
Later, I can simply import libraries I want
from my_package.numpy_1_15 as np115
from my_package.numpy_1_16_4 as np1164
and later in my code, I can decide which function to use from which numpy version. For example:
index = np115.argwhere(x == 0)
This is my vision of the solution to my problem where I want to keep using old functions from previous versions of numpy (or other libraries). In addition, in this way, I can always have all the libraries needed with me in my script directory. So, if I need to run the script on a different machine I don't need to spend hours figuring out if everything is compatible.
Here are possible proposed solutions and why they do not solve my problem.
Virtual Environments in Python or Anaconda.
There are a bunch of introductions (for example) available that explain how to use them. However, virtual environments require maintenance and initial setup. Imagine, if I can just have a python code that performs well a specific computational task independent on what year it is and what packages are installed on any machine. The code can be shared among different research groups and will always work.
python create standalone executable linux
I can create standalone executable (example). However, it will be compiled​ and cannot be dynamically changed the really nice feature of Python

Plot in python without matplotlib

I'm writing a program for TopSpin, an NMR processing software from Bruker. TopSpin runs the python scripts in it's own environment using jython. The python version it returns is 2.5.* (I don't remember the last one).
import sys
print(sys.version)
>> 2.5.*
As the code is executed in it's own environment, I cannot update the version of python/jython and I also cannot install missing packages.
For my current project I would need a functionality to plot the values of two lists. The first list on the x-axis and the second one on the y-axis.
For this task I wanted to use matplotlib's function plot(xlist, ylist). Unfortunately TopSpin throws an error at me, saying that the package matplotlib does not exist. As I can't install the package (or at least I have no idea how I should), I now need a workaround.
Is there a way I could call a python script that runs in the normal environment of my computer (like idle) where python 3.6.3 and matplotlib are installed? Ideally this could generate the plot and ship it back to the TopSpin python program.
Or is there an other workaround that enables me to plot my data and show it to the user/save it on the disk, that does not rely on fancy or new packages?

Directly open Spyder or open it through Pythonxy?

Previously, I have been running Python in Spyder. I always started Spyder by directly double clicking its icon.
Today, I suddenly realize that I have another thing called Python(x,y). I notice that I can also start Spyder through it.
Do these two methods make any difference?
If not, what is the meaning of Python(x,y)? Does it have any other good features?
Python(x,y)
Python(x,y) is a scientific Python distribution. This means that it not only installs Python in your system but also the most important scientific packages needed for a scientist to be productive with the language.
These packages are difficult to install by the user and also are too many to be installed one by one, so that's why Python(x,y) offers the possibility to install them all at once.
Spyder
Spyder is one of the packages distributed by Python(x,y), which offers a simple and convenient graphical environment to use the other scientific packages (like numpy or matplotlib). It resembles Matlab in its design.
Perhaps a comparison to Matlab is worth here:
Matlab is a huge program (about 5 gigs) that it's developed by one company and comes with a lot of packages and a graphical interface to use it.
Python(x,y) is also a big program (about 1 gig) but it's developed by two individuals who collect a lot of open source programs developed by a lot of different groups and institutions. It also comes with a graphical interface (Spyder) but there are others that fulfill a similar purpose (like the IPython notebook).
So in the Python scientific world, every package is developed independently of each other and there is the need of a "meta" program (like Python(x,y)) that distributes them together.
Actually i did not use spyder alone, but when you open it through Python(x,y) which is a scientific oriented distribution, some packages that are used in scientific/numeric computing automatically loaded.
Python(x,y) is based on python, Qt, spyder and includes many tools for scientific/numeric computation, visualizing (2D-3D), etc.
https://code.google.com/p/pythonxy/

Inconsistency between IDLE/PythonWin during module imports

I have been fumbling around between IDLE/PythonWin and even Aptana Studio 3 trying to get some consistency regarding importing modules. The modules I have been using lately are wx from wxPython and the arcpy module. IDLE will let me import arcpy, but not wx. PythonWin will let me import wx, but not arcpy.
When I do sys.executable in IDLE I get "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\Pythonwin.exe"
When I do sys.executable in PythonWin I get "C:\Python27\pythonw.exe"
Additionally, I am wondering if I am using different interpreters, how to set them all to the same one, and which one to use.
I have been learning and using Python for a little over half a year now and am at the point where I would really like to have these kinds of issues under control.
edit: lesson learned years later: use pycharm and let it keep your environments separate for you! lol
The problem is that ArcGIS comes with its own specific Python bundled with the software and you have installed a normal distribution into "C:\Python27\". I would try removing the latter and reinstalling wxPython. I'm guessing this IDLE of which you speak is actually embedded in ArcGIS rather than being the normal IDLE.
To be more clear, when you originally installed wx, it saw the Python in "C:\Python27\" and installed in that location. If you can't get wx to install to the GIS location, there may be a way to fake it by just copying the wx folder from C:\Python27\ and putting it in ArcGIS. They should both be in something like "C:\Python27\Lib\site-packages\wx-2.9.3-msw" (depending on version) and there's also a wx.pth file you'll need to copy from ""C:\Python27\Lib\site-packages" to the same basic location in the GIS directory.
EDIT: I also found the following links that might address your issue:
http://www.scoop.it/t/arcpy/p/1759717424/custom-wxpython-gui-s-an-approach-for-arcgis-10-1-arcgis-resource-center
http://forums.arcgis.com/threads/41809-wxPython-hooked-to-arcmap
wxPython and ARCGIS
It sounds like you have to add wxPython as an add-in.

How can I run online python code that requires a set of modules?

How can I run online python code that owns/requires a set of modules? (e.g. numpy, matplotlib) Answers/suggestions to questions 2737539 and 3356390 about interpreters in python 3, are not useful because those compilers don't work properly in this case.
I found one that supports multiple modules, i checked numpy, scipy, psutil, matplotlib, etc and all of them are supported. Check out pythonanyware compiler, a sample console is here, however you can signup for accounts here, i believe there is a free version. I remember i used that that online compiler last year and it worked quite well, but for a free account it has certain limits. It also has a bash console, which allows you to run the python files.
You may try this as sandbox, it support numpy as well: http://ideone.com
You can try one of the best editors I found on internet , which has not only your requirements but more than that.
Here is the link - Replit

Categories