analitics

Pages

Saturday, November 28, 2015

The svgwrite python module - part 001.

The svgwrite python module is a tool by Manfred Moitzi.
To install this python module use Python 3.4 version.
Then you need to install svgwrite with pip3.4:
C:\Python34\Scripts>pip3.4.exe install svgwrite
Collecting svgwrite
  Downloading svgwrite-1.1.6.tar.gz (109kB)
    100% |################################| 110kB 354kB/s
Also this svgwrite is the only module that needs to be imported and then you can deal with this module.
See this simple example:
import svgwrite
from svgwrite import *
#this will work with svgwrite
svg_doc = svgwrite.Drawing(filename = "test-svgwrite.svg",\
                                size = ("30px", "30px"))\
svg_doc.add(svg_doc.rect(insert = (0, 0),\
                                   size = ("20px", "20px"),\
                                   stroke_width = "1",\
                                   stroke = "green",\
                                   fill = "rgb(255,255,0)"))\
print(svg_doc.tostring())
svg_doc.save()
The result of this python script is this SVG file.

If you use the dir() then you can see more about this python module:
>>> dir(svgwrite)
['AUTHOR_EMAIL', 'AUTHOR_NAME', 'CYEAR', 'Drawing', 'Hz', 'Unit', 'VERSION', '__
builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__p
ackage__', '__path__', '__spec__', 'animate', 'base', 'cm', 'container', 'data',
 'deg', 'drawing', 'elementfactory', 'em', 'etree', 'ex', 'filters', 'grad', 'gr
adients', 'image', 'inch', 'kHz', 'masking', 'mixins', 'mm', 'params', 'path', '
pattern', 'pc', 'percent', 'pt', 'px', 'rad', 'rgb', 'shapes', 'text', 'utils',
'validator2', 'version']
For example you can add some text:
svg_doc.add(svg_document.text("This add new svg text",\
                                   insert = (10, 10)))

Sunday, November 22, 2015

The new Python 2.7.11rc1.

The next release in the 2.7.x series is now available with the version 2.7.11.rc.1 .
This can be download it from here.
Come with source release, installer for Windows, Mac OS X 10.6 and later.
I don't use linux instalation, just on Windows 10 - 64 MSI installer.
The changes of this version can be see here.
First I saw this python version will change my old python 2.7 version.

Also I check to compile all python scripts and module.
With installed Python 2.7 I check if is all ok.

C:\Python27>python.exe
Python 2.7.11rc1 (v2.7.11rc1:82dd9545bd93, Nov 21 2015, 23:25:27) [MSC v.1500 64
 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Also I got a list of all available modules...
No handlers could be found for logger "OpenGL.Tk"
ImportError: numpy.core.multiarray failed to import
BaseHTTPServer      audioop             imaplib             scrap
Bastion             base                imghdr              select
BeautifulSoup       base64              imp                 sets
BeautifulSoupTests  bdb                 importlib           setuptools
CGIHTTPServer       binascii            imputil             sgmllib
Canvas              binhex              inspect             sha
ConfigParser        bisect              io                  shellescape
Cookie              bs4                 itertools           shelve
Dialog              bsddb               joystick            shelve_test
DocXMLRPCServer     bufferproxy         json                shlex
FileDialog          bz2                 key                 shutil
FixTk               cPickle             keyword             signal
HTMLParser          cProfile            lib2to3             simplejson
MimeWriter          cStringIO           linecache           site
Naked               cached_property     locale              six
OpenGL              calendar            locals              smtpd
PIL                 camera              logging             smtplib
PySide              cdrom               mac_scrap           sndarray
Queue               cgi                 macosx              sndhdr
ScrolledText        cgitb               macpath             socket
SimpleDialog        chunk               macurl2path         sprite
SimpleHTTPServer    cmath               mailbox             sqlite3
SimpleXMLRPCServer  cmd                 mailcap             sre
SocketServer        code                markupbase          sre_compile
StringIO            codecs              marshal             sre_constants
Tix                 codeop              mask                sre_parse
Tkconstants         collections         math                ssl
Tkdnd               color               md5                 stat
Tkinter             colorama            mhlib               statvfs
UserDict            colordict           midi                string
UserList            colorsys            mimetools           stringold
UserString          commands            mimetypes           stringprep
_LWPCookieJar       compat              mimify              strop
_MozillaCookieJar   compileall          mixer               struct
__builtin__         compiler            mixer_music         subprocess
__future__          constants           mmap                sunau
_abcoll             contextlib          modulefinder        sunaudio
_arraysurfarray     cookielib           mouse               surface
_ast                copy                movie               surfarray
_bisect             copy_reg            msilib              surflock
_bsddb              crypto              msvcrt              symbol
_camera             csv                 multifile           symtable
_camera_opencv_highgui ctypes              multiprocessing     sys
_camera_vidcapture  curses              mutex               sysconfig
_codecs             cursors             netrc               sysfont
_codecs_cn          cv                  new                 tabnanny
_codecs_hk          cv2                 newbuffer           tarfile
_codecs_iso2022     datetime            nmovie              telnetlib
_codecs_jp          dateutil            nntplib             tempfile
_codecs_kr          dbhash              nt                  test
_codecs_tw          decimal             ntpath              test27
_collections        decorator           nturl2path          test_crypto_python
_csv                difflib             numbers             tests
_ctypes             dircache            numpy               textwrap
_ctypes_test        dis                 oauth2client        this
_dummybackend       display             opcode              thread
_elementtree        distutils           operator            threading
_freetype           docs                optparse            threads
_functools          doctest             os                  time
_hashlib            draw                os2emxpath          timeit
_heapq              dumbdbm             overlay             tkColorChooser
_hotshot            dummy_thread        parser              tkCommonDialog
_io                 dummy_threading     pdb                 tkFileDialog
_json               easy_install        pickle              tkFont
_locale             ecdsa               pickletools         tkMessageBox
_lsprof             email               pip                 tkSimpleDialog
_markerlib          encodings           pipes               toaiff
_md5                ensurepip           pixelarray          token
_msi                errno               pixelcopy           tokenize
_multibytecodec     event               pkg_resources       trace
_multiprocessing    examples            pkgdata             traceback
_numericsndarray    exceptions          pkgutil             transform
_numericsurfarray   extraction          platform            ttk
_numpysndarray      fastevent           plistlib            tty
_numpysurfarray     filecmp             popen2              turtle
_osx_support        fileinput           poplib              types
_pyio               fnmatch             posixfile           unicodedata
_pytest             font                posixpath           unittest
_random             formatter           pprint              uritemplate
_sha                fpformat            profile             url-scrap
_sha256             fractions           pstats              urllib
_sha512             freetype            pty                 urllib2
_socket             ftfont              py                  urllib3
_sqlite3            ftplib              py_compile          urlparse
_sre                functools           pyasn1              urwid
_ssl                future_builtins     pyasn1_modules      user
_strptime           gc                  pyclbr              uu
_struct             genericpath         pycuda              uuid
_subprocess         get-pip             pydoc               version
_symtable           getopt              pydoc_data          vidcap
_testcapi           getpass             pyexpat             virtualenv
_threading_local    gettext             pygame              virtualenv_support
_tkinter            gfxdraw             pypm                warnings
_vlcbackend         glob                pysideuic           wave
_warnings           googleapiclient     pytest              weakref
_weakref            gp2x                pytools             webbrowser
_weakrefset         gzip                pytz                wheel
_winreg             hashlib             quopri              whichdb
abc                 heapq               random              winsound
aifc                hmac                re                  wsgiref
antigravity         hotshot             rect                xdrlib
anydbm              html5lib            repr                xlsxwriter
apiclient           htmlentitydefs      requests            xml
appdirs             htmllib             rexec               xmllib
argparse            httplib             rfc822              xmlrpclib
array               httplib2            rlcompleter         xxsubtype
ast                 idlelib             robotparser         yaml
asynchat            ihooks              rsa                 yt
asyncore            image               runpy               zipfile
atexit              imageext            rwobject            zipimport
audiodev            imageop             sched               zlib

Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".
I update some module with pip2.7
C:\Python27\Scripts>C:\Python27\python.exe
Python 2.7.11rc1 (v2.7.11rc1:82dd9545bd93, Nov 21 2015, 23:25:27) [MSC v.1500 64
 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
>>> from subprocess import call
>>>
>>> for dist in pip.get_installed_distributions():
...     call("pip2.7.exe install --upgrade " + dist.project_name, shell=True)
...
Requirement already up-to-date: appdirs in c:\python27\lib\site-packages
0
Requirement already up-to-date: BeautifulSoup in c:\python27\lib\site-packages
0
Collecting beautifulsoup4
  Downloading beautifulsoup4-4.4.1-py2-none-any.whl (81kB)
    100% |################################| 81kB 327kB/s
Installing collected packages: beautifulsoup4
  Found existing installation: beautifulsoup4 4.3.2
    Uninstalling beautifulsoup4-4.3.2:
      Successfully uninstalled beautifulsoup4-4.3.2
Successfully installed beautifulsoup4-4.4.1
0
Some python modules has problems with update...

  Failed building wheel for pycuda
Note:
I think the python has some problems with keep and clean correct modules under pip.
Also I guest can be done with few rows of python scripts but also this can be done by default by python installation.

Sunday, November 8, 2015

WinPython - news and old stuff.

First good news: the team tells us about the WinPython will come with new release of WinPython.
This will be 3.4.3.7 version of WinPython and this will be great for most of users.
I love this portable python because first is easy to use and can easy test my python scripts.
One goal of this portable python it's the demos. I found some great demos with PyQt4 and networkx.

Also you can use Spyder to make your python scripts.
It's a free open-source development environment for the Python programming language.
This visual interface similar to MATLAB where you can run commands, edit and debug programs, check the values of variables and the definitions of functions, etc.
If you just getting started with Python then just take a look at google.com/edu/python.
The WinPython Control Panel allows to register your WinPython distribution to Windows with Advanced - Register distribution ...:
...and this allow you to:
  • associate file extensions .py, .pyc and .pyo to Python interpreter
  • register Python icons in Windows explorer
  • add context menu entries Edit with IDLE and Edit with Spyder for .py files
  • register WinPython as a standard Python distribution in the registry (the same way as the standard Python Windows installers will do)
Also you can use Jupyter Notebook web application.
This allow you to:
The Jupyter Notebook is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, machine learning and much more.