|using script as both library and executable in python packages|
Make it a normal .py module so it can be imported, and define an entry
point. Automatic script creation will take care of creating a script in bin
that will call the entry point method.
|pip installs packages, but doesn't mark them as executable, so python doesn't find them|
You best bet is virtualenv Do your workaround to install the virtualenv.
sudo pip install virtualenv
Resources for virtualenv to get you started:
|how to honor the parent logging namespace when importing python modules from entry points|
How is the plugin supposed to know whether it's part of application foo as
opposed to application bar? If you don't want your plugins to be part of
the foo namespace, you can just attach your handlers to the root logger and
you won't get the message about "no handlers could be found".
|python packages -- overriding built-in packages and the dreaded "Module xxxx was already imported" warning|
Rename myprogramxlrd to myprogramfrozen_xlrd.
Then import it with
import frozen_xlrd as xlrd
Alternatively, you could tell Python to silently ignore this particular
message="Module xlrd was already imported",
Place this early on in the program, before scikits gets imported.
|Does virtualenv isolate python itself + python packages, or just python packages?|
Virtualenv installs python, but it's installed in the bin directory of the
virtualenv you created. Therefore you need to run it with ./bin/python.
You can also "activate" the virtualenv by running
Which will put the virtualenvs bin directory first in the path (and do some
other trickery I think) which will make the virtualenvs Python the default
Python, so you can start it with just python. But this is not necessary.
|package code.google.com/p/go.example/hello: exec: "hg": executable file not found in %PATH%. How to get remote golang packages?|
The package you are trying to install is under the Mercurial (hg) source
control system. You need to install Mercurial to be able to clone the
|Python Tkinter - How to place the input from an entry using entry.get()|
Like the error message says, user is a string and not a widget. Hence it
doesn't have a place method like username and submit. You want to stick it
into a label and then place the label.
|Plot missing points for complicated 3D list of points - Python|
The general approach that you linked to will work fine here ; it looks like
the question you're asking is how to apply that approach to your data. I'd
like to suggest that by factoring out the data you're plotting, you'll see
more clearly how to do it.
import numpy as np
y_data = [
x_data = [0, 1, 2, 3, 4]
for i in range(5):
xv = 
yv = 
for j, v in enumerate(row[i] for row in y_data):
if v is not None:
ax.plot(xv, yv, label=y_data[i])
Here instead of using a mask like in the linked question/answer, I've
explicitly built up the lists of valid data points that are to b
|How to distribute a stand-alone python application?|
Why don't you create a directory with the interpreter you want to use, add
in any modules etc. Then drop in a bash script, say run.sh which calls the
program. It can launch your chosen interpretter with your python files,
Any source files can remain this way and be edited in place. You could tar
and distribute the whole directory, or put in something like git.
|Compiling shared library for python to distribute|
I've been getting the same error/having the same problem. I'd be interested
if you've found a solution.
I have found that if I compile against the native python include directory
and run the native OS X python binary /usr/bin/python that it works just
fine, always. Even when I compile against some other python library (like
the one I find at
) I can get the native OS X interpreter to work just fine.
I can't seem to get the Enthought version to work, ever. What directory are
you compiling against for use with Enthought/Canopy?
There also seems to be some question of configuring SWIG at installation to
know about a particular python library, but this might not be related:
|Algorithm for Finding a circle among 2n+3 points such that it contains n points inside, n points outside and 3 points on itself|
You could consider using a QuadTree: Quadtree on wiki
Then using this structure you could scan the proximity of each node. There
seems to be a function called Query Range. This function will allow you to
be more precise than just exhaustively picking circles I think.
Note this is not the solution, just an idea to get you started.
|How to create windows 32/64 executable for a python script written in python 3.3.2?|
I found following useful links and cx_Freeze worked like a charm with a
python script written in python 3.3.2.
Thanks to all for providing the useful information.
Useful replies for converting python script in 3.3.2 to windows executable.
Download cx_Freeze and see relevant documentation.
Once cx_Freeze is installed, use this link for other instructions.
|Where shall I put my self-written Python packages?|
I'd use the home scheme for this:
|Testing Python Packages|
You can use pip -e install <path-to-package> to install a package in
editable mode. Then, you can make changes to the source code, and not have
to install it again.
This is best done, as always, in a virtualenv, so it is isolated from the
rest of your system.
|How to invoke C executable file using Python|
Per Comments the answer was:
Use forward slashes '/usr/bin/app'
Personally though I would strongly consider using os.path.join or str.join
and os.sep so you don't have to remember which way the slashes should go.
|Creating a python executable using py2exe|
I woul recommend you create a module (ExistGUI) with the following
Your init.py should have:
from . import localsettings, Tryone
__version__ = 1.0
Your setup.py should look something like:
from setuptools import setup, find_packages
name = 'ExistGUI',
version = ExistGUI.__version__,
description = 'Python eXistdb communicator using eulexistdb module',
author = 'Sarvagya Pant',
py_modules = ['localsettings','Tryone'],
Then run python setup.py py2exe. Make sure you include a
|converting python program into executable|
If you want to make it executable, you have to chmod +x /path/to/script.py.
This gives anybody permission to run the file. Then you can python
You still need to start the command with python, that is ugly. If you add
this line #!/usr/bin/env python to the first line of your script. This is
callled a shebang or a hashbang. Then (still remember to chmod it) you can
/path/to/script.py and it will execute.
If you are already in the directory of your script you can ./script.py.
(still remember to chmod it and at a shebang)
If you still aren't satisfied, and you want to type in just the name of
your script, you move the script into one of the folders on your path
(which you can find by typing echo $PATH in shell, typically this is /usr/,
/bin/, /usr/local/bin, or something
|Installer for Python Executable on Windows|
I developed a Python/GTK/OpenGL based desktop application in the past and
in order create the executable and an installer I've used PyInstaller +
NSIS is what you're asking for: it's quite flexible, you may want to give a
|How to parse flags to a Python executable?|
rename /opt/local/bin/python to /opt/local/bin/python2
create a shellscript that parses your flags and calls python2. name it
although thats going to be a pain if you are trying to distribute your
script with those options
|How do I make Python script executable?|
One thing I am pretty sure you can do, though it's fragile and is not that
suitable for deploying across multiple users, is make a shortcut to your
Python.exe binary and edit the shortcut command line to be something like:
"C:Python31python.exe" <path to your script>
The main problem with this, and the reason it's not very desirable, is that
each copy needs to be modified if the paths change.
Another possibility is to wrap the Python script's execution in a .bat
Shashank Gupta, in comments above, also recommends checking out cxfreeze.
I haven't used this tool, but it might work for you.
|Testing an executable in a Python package|
Within the package, you can directly import __init__ and then rename with
as. Try this
import __init__ as foo
in place of
|Installing Python Packages - IronPython|
You have to run IronPython with the command line option -X:FullFrames. I'm
not sure, though, how to set that up in the VS.
Maybe you can manually run it:
C:path oipy64.exe -X:FullFrames path opip.py install whaterver_you_want
|python | heroku | how to access packages over ssh|
I had the same issue before I wanted to use django-avatar and the version
in PyPI is old and doesn't support Django 1.5 Custom User .
The simple solution is to download the package and use it as a regular app
as if it was part of your project then just git add . and push it and it
It might not be the best idea but it just works .
|Proper permissions for python packages|
It happens when sdist tarball is generated with a restrictive umask or when
files were created without others/nobody read/execute permissions.
A simple workaround is to broak the umask bits and chmod files before
umask 0022 && chmod -R a+rX . && python setup.py sdist
|Identify directories that are packages in Mac OS X with Python|
OS X packages (and bundles) are usually defined by their extension. Simply
create a directory with an .app extension to see it be presented as a
(broken) application in the Finder.
The official documentation lists the following ways to define bundles:
The Finder considers a directory to be a package if any of the following
conditions are true:
The directory has a known filename extension: .app, .bundle, .framework,
.plugin, .kext, and so on.
The directory has an extension that some other application claims
represents a package type; see “Document Packages.”
The directory has its package bit set.
The preferred way to specify a package is to give the package directory a
known filename extension. For the most part, Xcode takes care of this for
you by providing tem
|Python: How to import sub-modules, from packages with the same name?|
You need to have _init_.py files within those directories to make python
treat then as a package instead of plain directories.
Refer to this discussion to learn more about init.py files.
Note:I have edited my previous answer by removing the irrelevant content
based on the discussion with the poster of the query.
|Python - download packages from own server|
From the docs, you can use the:
--use-mirrors --mirrors <url>
flag in pip to specify which mirror to use.
From command line, you can also speicify mirrors. For example:
pip install -i http://d.pypi.python.org/simple $PACKAGE
|Installing python packages in nitrousio|
You could try pip install --user praw
|Securely Send Email from Python Executable|
One possible solution is to create a web backend mantained by you which
accepts a POST call and sends the passed message only to authorized
This way you can also mantain the list of email addresses on your server.
Look at it like an online error alerter.
|How to make a Python script an executable program|
If you just need to make the python programs executable, then you can add a
line to the top like this:
Replace /usr/bin/python with the filepath to python, which can be obtained
into the terminal, assuming you're using a unix-based system.
You can then tell the operating system that the program is executable with
chmod +x nameofprogram
If the java programs require something more complicated than just being
able to run the python parts as executables, then you'll probably need to
provide more information for anyone to be able to help you.
|python how to build an executable with ffmpeg and lame|
See this wikipedia List of installation software.
I have used Install4j (costs $2K) and IzPack (free); both require the JVM,
and a few days each of testing and experimentation. There are other options
that don't appear to require JVM.
While your current target is OSX, if you are considering multi-platform it
is well worth testing on Linux and Windows from the start.
How to go about it? Build up a sample installation, then use the tool to
bundle it up and install on the target machine. And test, test, test.
Spend some time thinking about what kind of future change you want to
support (that's where the multi platform bit helps), and what minimum OS
version and machine config you require.
Finally: make sure you are complying with the licenses of both ffmpeg and
lame, and the tool you us
|Make a python program with PySide an executable|
You are missing a DLL. The DLL in question can be (at least formerly)
obtained from Microsoft by downloading their free compiler package.
Alternatively, ensure that this process has the right paths set to find the
DLL in question.
|How to turn Python program into executable file|
Here are a few options:
Platypus is not Python-specific. It lets you wrap a simple GUI around a
command line tool.
py2app is Python-specific and a good choice if you have a GUI, or need to
run in the background.
PyInstaller is similar to py2app but cross-platform; I've never used it, so
I don't know how well it works.
The right choice depends on what your program does; who is the expected
audience — do you need to redistribute it, if so how, and so forth. If
you want to make the application entirely self-contained — not dependent
on anything else beyond the OS — then things get more complicated (though
certainly not insoluble; there are several commercial Mac desktop apps
written in Python.)
|ttk Entry widget - validate entry - invalid text entry does not cause reverting to previous text|
from tkinter import *
from tkinter.ttk import *
root = Tk()
text = StringVar()
vcmd = root.register(validate)
a = Entry(textvariable=text,
b = Entry()
I used validate='key' instead.
and replaced validate function. a in b check substring a in contained in b.
>>> '100.00' in '0123456789.-+'
>>> '100.00' in 'blah blah 100.00 blah blah'
from tkinter import *
from tkinter.ttk import *
root = Tk()
text = StringVar()
last_ok_value = text.get()
|Python: I can't import a module even though it's in site-packages|
I extracted the package and placed it in site-packages:
No, that's the wrong way of "installing" a package. Python packages come
with a setup.py script that should be used to install them. Simply do:
python setup.py install
And the module will be installed correctly in the site-packages of the
python interpreter you are using. If you want to install it for a specific
python version use python2/python3 instead of python.
|importing system in python - import packages|
Imports dir1's __init__.py. You can access whatever is there using
dir1.my_var_from_dir1_init. You cannot access the modules, only what's on
from dir1 import *
Imports the modules specified on the __all__ variable defined on dir1's
__init__.py. If there isn't such variable, then it imports all of dir1's
modules. You can access them directly, like main_code1.myvar.
from dir1 import maincode
Assuming it's a typo and you actually have a maincode module or class, it
imports the maincode module/class from dir1. You can access it directly
like mentioned above.
Note that each option imports dir1's __init__.py, implicitly or explicitly.
If you import the modules on __init__.py, then using import dir1 will allow
you to use dir1.module.
To import dir3's mainc
|Keeping Python packages with the same top-level name in different directories|
There are several options, one of which is imp:
foo = imp.load_source('module.name', '/path/to/file.py')
Another is with importlib
|Calling modules from different packages in a python Project|
Within the __init__.py file, put:
from myfile import *
Where the __init__.py would contain:
from parens import *
That's the dirty quick-fix version for older python versions.
Considering you have multiple subdirectories something along the lines of
(see blow) would be better for all python versions:
In your __init__.py in the folder test place:
__all__ = ['tacos','falaffels']
from test.tacos import factory
from test.falaffels import stand
If you have the following folder structure the above should work:
Also just noticed that this might be a duplicate of: How do I write
good/correct __init__.py files
|Mixing functions and subpackages in Python packages|
Solution #1: Try the following layout:
In this case Transform.fft goes inside lib/Transform/__init__.py and
Transform.bins.extent inside lib/Transform/bins.py
Solution #2: If you wish to keep __init__.py short and clean, you can also
create a separate Python-module (like fft.py) and import it in __init__.py
from fft import *
In which case you can also use:
from lib.Transform import fft
|python: import error after making program executable|
Your program is trying to run like a bash-script, so it seems, your
#!/usr/bin/env python had no effect. Make sure that this line is at the top
of the program in the first row with no characters before #