EzDevInfo.com

egg.js

A simple javascript library to add easter eggs to web pages.

What is a Python egg?

I'm new to Python and am just trying to understand how its packages work. Presumably "eggs" are some sort of packaging mechanism, but what would be a quick overview of what role they play and maybe some information on why they're useful and how to create them?


Source: (StackOverflow)

Is there a python equivalent of Ruby's 'rvm'?

Q: Do we have anything functionally equivalent in Python to the Ruby version manager 'rvm'?


(RVM lets you easily switch completely between different versions of the ruby interpreter and different sets of gems (modules). Everything concerning download-build-install-switch of interpreter(-s) and gems gets taken care of by invoking rvm. It is all run under your regular user account.)


Source: (StackOverflow)

Advertisements

How to run Python egg files directly without installing them?

Is it possible to run Python egg files directly as you can run jar files with Java?

For example, with Java you might dos something like:

$ java -jar jar-file

Source: (StackOverflow)

How to create Python egg file

I have questions about egg files in Python.

I have much Python code organized by package and I'm trying to create egg files. I'm following instructions, but they are very common.

According to that, it seems I need to have a setup.py file.

  1. Would you please tell me what I need to put into setup.py file and where it should reside?
  2. I suppose it's enough to create setup.py and then start "setup.py bdist_egg" for getting egg file. Could you please confirm?
  3. Is it possible to include only .pyc files into egg file?
  4. Having .egg file how I can just start the code from it without unpacking like java -jar <jar file> does?

Source: (StackOverflow)

How do I manage third-party Python libraries with Google App Engine? (virtualenv? pip?)

What's the best strategy for managing third-party Python libraries with Google App Engine?

Say I want to use Flask, a webapp framework. A blog entry says to do this, which doesn't seem right:

$ cd /tmp/
$ wget http://pypi.python.org/packages/source/F/Flask/Flask-0.6.1.tar.gz
$ tar zxf Flask-0.6.1.tar.gz
$ cp -r Flask-0.6.1/flask ~/path/to/project/
(... repeat for other packages ...)

There must be a better way to manage third-party code, especially if I want to track versions, test upgrades or if two libraries share a subdirectory. I know that Python can import modules from zipfiles and that pip can work with a wonderful REQUIREMENTS file, and I've seen that pip has a zip command for use with GAE.

(Note: There's a handful of similar questions — 1, 2, 3, 4, 5 — but they're case-specific and don't really answer my question.)


Source: (StackOverflow)

How to compare "version-style" strings

I am walking a directory that contains eggs to add those eggs to the Pythonpath (sys.path). If there are two versions of the same .egg in the directory, I want to add only the latest one.

I have create a simple regular expression (r"^(?P<eggName>\w+)-(?P<eggVersion>[\d\.]+)-.+\.egg$) to extract the name and the version of the egg. The idea is keeping the information in a dictionary and once the whole directory has been walked, adding only the highest version eggs. Keeping track of the egg files/directories to add is not the issue. The problem is comparing the version number, which is an string like... "2.3.1".

Since I'm comparing strings, this happens:

>>> "2.3.1" > "10.1.1"
True

But version 2 is not a higher version than version 10.

I know I could always start doing some splitting, parsing, casting to int, yadda, yadda, yadda... And I would eventually get a workaround but... there has to be a cleaner more effective (and elegant) way of comparing this. Is there? This is Python, not Java... there's an elegant way of doing this kind of thing... Right?

Also, the goal of all this is adding the right eggs to the Pythonpath so maybe I could go with a totally different approach using some kind of... egg handler package? That kind of answers are also welcome.

Thank you in advance.


Source: (StackOverflow)

Python packages and egg-info directories

Can someone explain how egg-info directories are tied to their respective modules? For example, I have the following:

/usr/local/lib/python2.5/site-packages/quodlibet/
/usr/local/lib/python2.5/site-packages/quodlibet-2.0.egg-info/

I'm assuming the egg-info directory is to make the corresponding module visible to setuptools (easy_install), right? If so, how does setuptools tie the egg-info directory to the module directory?

Assuming that I'm on the right track, and for the sake of example... If I wanted to make an existing package of mine visible to setuptools, could I just symlink the module directory and the egg-info directory to the site-packages directory? I would have just tried this myself, but I'm not sure how to test if the package is visible to setuptools. Bonus points if you can also tell me how to test this :)

The main reason I'm trying to understand all this is because I would like to symlink some of my modules into site-packages so that I can make changes to them and have the changes visible to the scripts that use them without having to reinstall the egg from PyPI after each change.


Source: (StackOverflow)

Where can I download binary eggs with psycopg2 for Windows?

I'm looking for binary eggs with psycopg2's binaries for Windows but can't find any.
On http://initd.org/psycopg/download/ there's only source package and link to Windows port of Psycopg which provides binary installers but no binary eggs.

The reason I'm looking for binary egg is I'd like to install psycopg in virtualenv and it's not (this answer describes why it usually is possible) possible with standard Windows installers which look for installed Python in the registry.

Side note: I guess psycopg is rather popular library and it strikes me as odd not to provide binary eggs for download on project's page. Am I missing something here?


Source: (StackOverflow)

Why does pip fail when installing local egg repository?

I am working on Windows 7.I have created a python egg using distutils. Now I try to install this egg in a virtual environment using pip 1.0.2 using the following command:

Then I create a virtual environment myVirtualEnv I activate it using activate.bat then execute the following command:

pip install path_to_my_local_folder#eggName

This creates a copy of my egg in my myVirtualEnv\build directory but I have the following error:

IOError: [Errno 2] No such file or directory: path_of_my_virtualEnv\build\PyEqdR\setup.py

Do you know why pip is looking for the setup.py file. Should I include it in the egg ?


Source: (StackOverflow)

What are simple instructions for creating a Python package structure and egg?

I just completed my first (minor) Python project, and my boss wants me to package it nicely so that it can be distributed and called from other programs easily. He suggested I look into eggs. I've been googling and reading, but I'm just getting confused. Most of the sites I'm looking at explain how to use Python eggs that were already created, or how to create an egg from a setup.py file (which I don't yet have). All I have now is an Eclipse pydev project with about 4 modules and a settings/configuration file. In easy steps, how do I go about structuring it into folders/packages and compiling it into an egg? And once it's an egg, what do I have to know about deploying/building/using it? I'm really starting from scratch here, so don't assume I know anything; simple step-by-step instructions would be really helpful...

These are some of the sites that I've been looking at so far:

I've also browsed a few SO questions but haven't really found what I need.

Thanks!


Source: (StackOverflow)

Most Pythonic way to provide global configuration variables in config.py?

In my endless quest in over-complicating simple stuff, I am researching the most 'Pythonic' way to provide global configuration variables inside the typical 'config.py' found in Python egg packages.

The traditional way (aah, good ol' #define!) is as follows:

MYSQL_PORT = 3306
MYSQL_DATABASE = 'mydb'
MYSQL_DATABASE_TABLES = ['tb_users', 'tb_groups']

Therefore global variables are imported in one of the following ways:

from config import *
dbname = MYSQL_DATABASE
for table in MYSQL_DATABASE_TABLES:
    print table

or:

import config
dbname = config.MYSQL_DATABASE
assert(isinstance(config.MYSQL_PORT, int))

It makes sense, but sometimes can be a little messy, especially when you're trying to remember the names of certain variables. Besides, providing a 'configuration' object, with variables as attributes, might be more flexible. So, taking a lead from bpython config.py file, I came up with:

class Struct(object):

    def __init__(self, *args):
        self.__header__ = str(args[0]) if args else None

    def __repr__(self):
        if self.__header__ is None:
             return super(Struct, self).__repr__()
        return self.__header__

    def next(self):
        """ Fake iteration functionality.
        """
        raise StopIteration

    def __iter__(self):
        """ Fake iteration functionality.
        We skip magic attribues and Structs, and return the rest.
        """
        ks = self.__dict__.keys()
        for k in ks:
            if not k.startswith('__') and not isinstance(k, Struct):
                yield getattr(self, k)

    def __len__(self):
        """ Don't count magic attributes or Structs.
        """
        ks = self.__dict__.keys()
        return len([k for k in ks if not k.startswith('__')\
                    and not isinstance(k, Struct)])

and a 'config.py' that imports the class and reads as follows:

from _config import Struct as Section

mysql = Section("MySQL specific configuration")
mysql.user = 'root'
mysql.pass = 'secret'
mysql.host = 'localhost'
mysql.port = 3306
mysql.database = 'mydb'

mysql.tables = Section("Tables for 'mydb'")
mysql.tables.users = 'tb_users'
mysql.tables.groups =  'tb_groups'

and is used in this way:

from sqlalchemy import MetaData, Table
import config as CONFIG

assert(isinstance(CONFIG.mysql.port, int))

mdata = MetaData(
    "mysql://%s:%s@%s:%d/%s" % (
         CONFIG.mysql.user,
         CONFIG.mysql.pass,
         CONFIG.mysql.host,
         CONFIG.mysql.port,
         CONFIG.mysql.database,
     )
)

tables = []
for name in CONFIG.mysql.tables:
    tables.append(Table(name, mdata, autoload=True))

Which seems a more readable, expressive and flexible way of storing and fetching global variables inside a package.

Lamest idea ever? What is the best practice for coping with these situations? What is your way of storing and fetching global names and variables inside your package?


Source: (StackOverflow)

How do I turn a python program into an .egg file?

How do I turn a python program into an .egg file?


Source: (StackOverflow)

How does Python keep track of modules installed with eggs?

If I have a module, foo, in Lib/site-packages, I can just import foo and it will work. However, when I install stuff from eggs, I get something like blah-4.0.1-py2.7-win32.egg as a folder, with the module contents inside, yet I still only need do import foo, not anything more complicated. How does Python keep track of eggs? It is not just dirname matching as if I drop that folder into a Python installation without going through dist-utils, it does not find the module.

To be clearer: I just installed zope. The folder name is "zope.interface-3.3.0-py2.7-win32.egg". This works:

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import zope.interface
>>>

I create a "blah-4.0.1-py2.7-win32.egg" folder with an empty module "haha" in it (and __init__.py). This does not work:

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import blah.haha
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named blah.haha
>>>

This does, though:

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pkg_resources import require
>>> require("blah>=1.0")
[blah 4.0.1 (c:\python27\lib\site-packages\blah-4.0.1-py2.7-win32.egg)]
>>> import haha
>>>

So how do I make it work without a require?


Source: (StackOverflow)

Python: If there are multiple egg versions of the same package installed, how do I import specifically the version I need?

Say, for example that FooPackage-1.1 and FooPackage-1.2 are both installed in dist-packages as eggs. How do I import the one I need?


Source: (StackOverflow)

What is the point of Python egg files?

When I run python setup.py install django, it generates an egg file.

What is the usefulness of Python egg files?


Source: (StackOverflow)