Using pypy instead of psyco - python-2.7

Hi I am trying to make use of pypy on my Python 2.7 application running in windows XP.
Just read a little on psyco and it seems pretty easy to use see http://psyco.sourceforge.net/psycoguide/node8.html
if __name__ == '__main__':
# Import Psyco if available
try:
import psyco
psyco.full()
except ImportError:
pass
# ...your code here...
However I realised that psyco doesn't support python 2.7, shame, so pypy being the new hotness, I was wondering how to make use of it in my application. I can't seem to see how I "import" it and make it work as the example above.
My application is not just a single .py file but an entire text editor I am writing using pyqt, I would very much like to speed things up.
Any suggestions of how to use pypy similar to the above code
Any alternatives that would allow me to do something similar to the above?
Many thanks
I just want to clarify, maybe it wasn't clear earlier. currently i use py2exe to create an executable of my application. I have a setup.py file and I run python setup.py py2exe, this creates the executable that I distribute. Now I want to speed up the application so that when I distribute it, the entire application runs faster.
Now how do I make use of pypy again to create a faster executable application that I can distribute?

Pypy is run instead of the CPython executable.
So, when you up until now ran
python mypythonfile.py
Or similar, with pypy you just run
pypy mypythonfile.py
It is a drop-in replacement. You do not need to import anything, especially not psyco

Related

ee.mapclient with python 2.7 and Anaconda, possible alternatives?

I have installed the google earth engine python APIs in my MAcOS where also Anaconda is installed. I got problem with the object ee.mapclient. I made it working modifying the line of the import using
from PIL import Image, ImageTk
Now it does not produce error message but it is not working either. When I run a script in Spyder the console returns several message and it enters in loop.
Running the same script line by line in the console, a big black window is opened but nothing is displayed.
Is there any solution to make it working? I know that the developer is not maintaining this object because too dependent to TK libraries. Is there any other solution to display satellite data?

Kivy Configuration Ignored

I am working on Ubuntu 14.04 64bit. Default python 2.7.x package. Custom built Kivy (rather, it is not the kivy supplied in the repositories. I used pip to gather dependencies and build Kivy in a Virtualenv)
For some reason, I seem to have no control over a large portion of my runtime Configuration. I have tried using environment variables, kivi.ini in my working directory and home directory. I have tried directly importing the kivy.Config module at various different points in the runtime (before the Kivy App is built, during, after).
It seems that I cannot configure certain Kivi settings (default screen size for instance). My Kivy application is quite functional, but I am having trouble finding where Kivi looks for default configurations, and where the proper place is to override. I have tried many different ways, but it seems there is some master configuration that is taking priority and I am not able to override.
Am I missing something simple? Does this have anything to do with the virtualenv (and how Kivy was built)?
I have tried directly importing the kivy.Config module at various different points in the runtime (before the Kivy App is built, during, after).
If this is to work, it should be before anything else is imported.
Also, kivy is probably looking for the config file in ~/.kivy/config.ini.

How to configue Pydev test runner to use Docker

I am developing a Django app or two using pydev as my IDE. I like it a lot :) However, I recently got really excited about Docker and am using Docker and Fig to serve my application now. My problem is that I would like to run my tests in this build environment- seems like this is kinda the point after all!
I know how to actually do it.
fig run web python3 /code/manage.py test
would run the tests. If I didn't want to use the Django runner, I could run
fig run web python3 /code/myapp/tests.py
Either way though, I cannot figure out how to issue that command from the IDE. All of the run configurations point to the configured python.exe ... does anyone know if there is a way to replace that with a fully customized command?
Well, the PyDev launch configuration is really targeted towards running Python, but there are alternatives to running it through other ways:
Create an external tool run (run > external tools > external tools configuration): You should be able to run anything you want from there... the downside is that this isn't really integrated into PyDev, so, if you have stack-traces they won't be clickable (and you won't be able to debug either).
Create a launcher script which in turn uses subprocess to launch the command you want... if you redirect things tracebacks should be clickable. The downside is that you won't be able to create a debug session either -- but you can still use the remote debugging in this case (http://pydev.org/manual_adv_remote_debugger.html)
Improve PyDev to do that better... (i.e.: get the code: http://pydev.org/developers.html and add docker support to a project through fig -- it should be something close to org.python.pydev.django which has special integration for running in django -- with some tweaks to the start command line, even starting in debug mode directly can work here)... if you decide to go that route, you can create a feature request at https://sw-brainwy.rhcloud.com/tracker/PyDev/ and ask code-related stuff and I'll help :)
Possibly you can create a custom executable which acts like Python but in reality just forwards things to other places (i.e.: to fig run) -- I haven't actually tested this, but in theory it should work (in the past there was work to support dummy 'python' runners such as that -- i.e.: for supporting http://cctbx.sourceforge.net/ -- so, it should work -- but you still have to create this launcher script for your use case to pass things to fig run). If the work is done properly, the debugger could work here too.

Using pygame via Sublime Text on mac 10.8 [duplicate]

This question already has answers here:
pygame installation issue in mac os
(5 answers)
Closed 2 years ago.
I'm using Python 2.7 32 bit and have a few questions about pygame on mac.
Where do the files go when you install it? I'm not given a choice for the file path when I install it.
When I import pygame in IDLE everything works fine (except it's a bit slow to load sometimes), but when I import pygame and run Python using Sublime Text (what would this be called, the key board short-cut is command-b for build), it can not find pygame. I'm assuming I have to find the library and move it to a different place but I can't find it.
When I run a file that imports pygame in the terminal everything works out fine too. Maybe there's a better text editor to use?
I'm new to programming and I'm realizing that its probably a good idea to get more acquainted with how my mac works/ is organized. Any good resources for this?
Just go to Tools->Build System->New Build System and make sure the json file that pops up looks exactly like this:
{
"shell_cmd": "python2.7-32"
}
Save it as "python2_32.sublime-build" or something that lets you know what it is, then you can go to tools->Build System and select your new build directive. Now when you Command-B, your code should run fine.
This essentially lets sublime text know that you want to run this script using the 32 bit version of python (which supports pygame). It's like a shebang for sublime.
Good luck!

Debugging Django from the command-line

I'm working on debugging Django from the command-line. I'm working with django_extensions, and I have IPython installed and ideally I'd like to be able to extract as much information in the shell as possible. How would I go about this task most efficiently?
As mentioned by Geo manage.py shell is good but since you have django_extensions already installed then Carl's suggestion of manage.py shell_plus is even better... saves a ton of typing.
But, as a third suggestion that is a bit less general, you might also want to check out django-viewtools. I personally tend to use shell_plus, but this might be useful.
If you have django_extensions installed, use
python manage.py shell_plus
to get all of your model classes automatically pre-loaded.
How about:
python manage.py shell
More info here
My favorite ways of debuging django problems is using the ./manage runserver_plus command to the django_extensions. It uses the Werkzeug debuger, which gives you a python shell in the web browser itself. If you want a shell anywhere in the code, just type some bogus python, like a simple a, and you will get a shell when that code is executed.
Another nice tool is ipdb ipython debugger. Its the same as pdb but better (and uses ipython. With this, and runserver_plus, you can insert import ipdb; ipdb.set_trace(), and you will get a ipython shell with an debugger in the same window as you have runserver_plus.
Take a look at http://docs.python.org/library/pdb.html#debugger-commands for a list of commands you can use inside the debugger.