ZeroRPC and IronPython - python

I would really like to use the excellent zerorpc for my project that uses IronPython, but it doesn't seem to be supported.
I have tried downloading the zip of the source for zerorpc and running
"C:\Program Files (x86)\IronPython 2.7\ipy.exe" setup.py install
but I see this along the way:
warning: build_py: byte-compiling is disabled, skipping.
This does not contradict the answer: Fast and scalable RPC between C# and CPython.
My question(s):
Is it possible to get zerorpc running with IronPython and if so, please could you give me a hint of how to do it?
If not, then are there any other equivalent packages that would provide the functionality in IronPython? There's a list here: What is the current choice for doing RPC in Python?, but does anyone know if any of these work with IronPython?
Update 2
Following #PawelJasinski suggestion and his updates to pyzmq ironpython-backend, I have tried the following:
Installed IronPython 2.7.5b2 or later
Installed 32 bit version of zeromq from http://zeromq.org/distro:microsoft-windows
Clone ironpython-backend branch from https://github.com/paweljasinski/pyzmq/tree/ironpython-backend
In pyzmq dir, run ipy.exe setup.py install --user
Clone zerorpc from https://github.com/dotcloud/zerorpc-python
In zerorpc-python, run ipy.exe setup.py install --user
Set the environment variable: set PYZMQ_BACKEND=zmq.backend.ctypes
Attempted to use the 'Cooler' class example from https://github.com/dotcloud/zerorpc-python, running with ipy.exe -X:Frames cooler.py
(cooler.py):
class Cooler(object):
""" Various convenience methods to make things cooler. """
def add_man(self, sentence):
""" End a sentence with ", man!" to make it sound cooler, and
return the result. """
return sentence + ", man!"
def add_42(self, n):
""" Add 42 to an integer argument to make it cooler, and return the
result. """
return n + 42
def boat(self, sentence):
""" Replace a sentence with "I'm on a boat!", and return that,
because it's cooler. """
return "I'm on a boat!"
import zerorpc
s = zerorpc.Server(Cooler())
s.bind("tcp://0.0.0.0:4242")
s.run()
Now I see this error:
Traceback (most recent call last):
File "C:\Users\nlindop\AppData\Roaming\Python\IronPython27\site-packages\zmq\backend\select.py", line 26, in select_backend
File "C:\Users\nlindop\AppData\Roaming\Python\IronPython27\site-packages\zmq\backend\ctypes\__init__.py", line 26, in <module>
File "C:\Users\nlindop\AppData\Roaming\Python\IronPython27\site-packages\zmq\backend\ctypes\constants.py", line 16, in <module>
ImportError: No module named ZMQ

ZeroRPC appears to be pure python and is based on pyzmq. In this case you can try pyzmq ctypes backend for IronPython. https://github.com/paweljasinski/pyzmq/tree/ironpython-backend
use IronPython 2.7.5b2 or newer
install 32-bit version of zmq from http://zeromq.org/distro:microsoft-windows
install pyzmq itself, clone, than ipy.exe setup.py install --user. Install should detect your zmq and pick the right dll
activate the ctypes backend, set the environment variable PYZMQ_BACKEND=zmq.backend.ctypes
UPDATE: ZeroRPC has dependency on gevent which is not available under IronPython, so the above instructions are valid only for pyzmq under IronPython

For the second part of the question. pyro (and its dependency serpent) support IronPython and Jython.
Warning: stay away from IronPython 2.7.5b3 - it has a bug which breaks serpent. 2.7.4 and 2.7.5b2 are ok. Next 2.7.5 has a fix.

Related

Installing SIP for Python 2.7 on windows 10

I have seen many threads that have a high level of ambiguity and go off on tangents from the original question, often assuming much about the authors ability, so I am hoping that if I am direct and concise with my information, I will get an answer that is in line with the requirement. I know that the serious programmers will have seen this many times, in many formats, so please just bear with me as this is doing my head in. Please do not just post a link to some other answer as I rarely find that helps with my current issue.
I am not a hardcore programmer, I find the compiling, sourceball, tar, gz all nonsense to be honest and am looking for the easiest way to install sip for python on my machine. I have installed various versions of mingw32, mingw64 to the point that I don't know which one is best to use. I am assuming that the one here: C:\Program Files\mingw-w64 is the one, considering I am using 64 bit, but do the others I have installed impact on this?
I also installed versions of mysys:
C:\msys\1.0,
C:\msys64, but I still m unclear what and why etc, despite trying to read the docs that came with them.
I have windows 10, 64 bit professional edition.
I have python 2.7
I have installs of mingw, 32 bit and 64 bit in various locations, due mostly to not fully understanding what exactly it was or where it should go. I found zips of it and exes, so I got a bit confused.
I downloaded the sip package and unpacked it to here: C:\Python27\Lib\site-packages\sip-4.19.3 and it has the configure.py file in it. So far, so good.
I used a CMD window, changed directory to: C:\Python27\Lib\site-packages\sip-4.19.3 and then used the command: python configure.py to create the Makefile file which is what I believe is supposed to happen.
I then opened the mingw64 shell, changed directory to the above sip folder and typed: python configure.py again, just to be sure I would get a response and create the files again, probably should not have done so, but hey ho, at this point, I am quite frustrated with it and trying to do anything with what I have, which I know is poor practice. (see image 1.)
image 1: configure.py executed
From what I have read, I should use the make function that comes with Mingw64, but I tried the following, which also includes the configure.py code, but nothing seems to work when trying to use the Makefile file that was created via the configure.py process.
c:\Python27>cd ./Lib/site-packages/sip-4.19.3
c:\Python27\Lib\site-packages\sip-4.19.3> python configure.py
This is SIP 4.19.3 for Python 2.7.13 on win32.
The SIP code generator will be installed in C:\Python27.
The sip module will be installed in C:\Python27\Lib\site-packages.
The sip.pyi stub file will be installed in C:\Python27\Lib\site-packages.
The sip.h header file will be installed in C:\Python27\include.
The default directory to install .sip files in is C:\Python27\sip.
Creating siplib\sip.h...
Creating siplib\siplib.c...
Creating siplib\siplib.sbf...
Creating sipconfig.py...
Creating top level Makefile...
Creating sip code generator Makefile...
Creating sip module Makefile...
c:\Python27\Lib\site-packages\sip-4.19.3> Makefile
'Makefile' is not recognized as an internal or external command,
operable program or batch file.
c:\Python27\Lib\site-packages\sip-4.19.3> make Makefile
make: Nothing to be done for `Makefile'.
c:\Python27\Lib\site-packages\sip-4.19.3> Makefile Makefile
'Makefile' is not recognized as an internal or external command,
operable program or batch file.
c:\Python27\Lib\site-packages\sip-4.19.3>
So now I am at an impasse. I have the locations of my mingw versions and the msys in my path environment variable and I have done just about everything I have looked at on the web. I realise that its an order of things, but I really wish there were just executables for these modules and supporting tools as this compiling is a ball ache.I tried opening a python shell and importing sip.
>>> import os, sys
>>> import sip
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import sip
ImportError: No module named sip
>>> import sipconfig
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import sipconfig
ImportError: No module named sipconfig
>>> from sip import sip
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
from sip import sip
ImportError: No module named sip
>>> from sipconfig impport sip
SyntaxError: invalid syntax
>>> from sip import *
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
from sip import *
ImportError: No module named sip
So, if anyone has read through this and has a definitive answer as to what I am doing wrong, I would appreciate it.
make/nmake or make/nmake install cant be done from cmd and python path; instead using mingw or visual studio tools.
In windows search for prompt or Visual studio tools to open VS Command promt and from there cd--> sip file location (before this run configure.py present in sip folder)
Now run the commands nmake and then nmake install

Installing PyGMO on Mac OS X Yosemite - missing boost-python3?

I've been trying to install PyGMO on my Mac OS X 10.10. I'm using Anaconda Python 2.3, so it comes with python 3.4.
I followed the instructions on http://esa.github.io/pygmo/install.html and did try to build boost manually but didn't have much luck with building boost-python... The instructions I could find on the official website was very limited...
While using ccmake to run the build file in pagmo/build directory, it complained that it did not find boost-python3...
So I reverted to using brew to install boost. Thanks to the info I found on this page: http://ryanclouser.com/2015/07/16/Mac-OSX-Build-Boost-Python-with-Python3-Support/
Now I have both boost and boost-python installed, but still the ccmake process for PyGMO complains about not being able to find boost-python3.
Are there any environment variables I need to set? In the ccmake config screen do I need to set Boost_PYTHON3_LIBRARY_RELEASE or Boost_PYTHON3_LIBRARY_DEBUG?
LATEST EDIT: This SHA256 below mis-match is resolved. Turned out it was caused by source forge site being down when I ran the commands... Some better error messages would have helped.
However, when I tried to get boost and boost-python with brew, I got the following SHA256 hash code mismatch error.
Anyone has any idea how to fix this?
>$ sudo brew install boost-python --with-python3
==> Installing boost-python dependency: boost
==> Downloading https://homebrew.bintray.com/b...
####################################################################### 100.0%
==> Pouring boost-1.58.0.yosemite.bottle.tar.gz
🍺 /usr/local/Cellar/boost/1.58.0: 10718 files, 486M
==> Installing boost-python
==> Downloading https://downloads.sourceforge....
==> Downloading from http://downloads.sourceforge.n...
####################################################################### 100.0%
Error: SHA256 mismatch
Expected: fdfc204fc33ec79c99b9a74944c3e54bd78be4f7f15e260c0e2700a36dc7d3e5
Actual: 818a4b8bbcb50878a8b1b9f71b4274d242ab46bf860c74676e98dec1d0248821
Archive: /Library/Caches/Homebrew/boost-python-1.58.0.tar.bz2
To retry an incomplete download, remove the file above.
Tried to delete the cached boost package files as suggested a few times but it didn't work either.
Thanks guys.
Ok problem resolved. Here's the best practice to get boost on Mac OS X.
Use Homebrew! but the key is to use the --with-python3 switch! Credits to this page: http://ryanclouser.com/2015/07/16/Mac-OSX-Build-Boost-Python-with-Python3-Support/
>$ brew install boost-python --with-python3
Assuming you have CMake already, just follow the instructions on PyGMO's website.
pagmo/build>$ ccmake ../
This will then bring up the config screen, everything should look fine. If not, do rm -rf * in pagmo/build folder to clear everything and start again (this resolved the issue with boost-python3 for me mentioned above.
Then run make and sudo make install as mentioned on the website.
PyGMO should be ready for use in python after that!
I had the following error message. However, if I start python in the ~/anaconda/lib folder where I have my anaconda installed, import PyGMO worked, so it's probably some library path thing that needs to be fixed.
>>> import PyGMO as gmo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/xxx/anaconda/lib/python3.4/site-packages/PyGMO/__init__.py", line 57, in <module>
from PyGMO import core, algorithm, migration, problem, topology, test, util
File "/Users/xxx/anaconda/lib/python3.4/site-packages/PyGMO/core/__init__.py", line 2, in <module>
from PyGMO.core._core import *
ImportError: dlopen(/Users/xxx/anaconda/lib/python3.4/site-packages/PyGMO/core/_core.so, 2):
Library not loaded: libpython3.4m.dylib
Referenced from: /Users/xxx/anaconda/lib/python3.4/site-packages/PyGMO/core/_core.so
Reason: image not found
**Latested EDIT: ** Did some searching around, a partial solution to the import error above, is to set DYLD_LIBRARY_PATH=~/anaconda/lib. With this, imports will work when you launch python in a console. However, IPython-notebook would not start for me... Also have seen that Max OS doesn't really have a dynamic search also...

import magic throws exception

So I used pip to download filemagic:
E:\cuckoo-current\cuckoo>c:\Python27\Scripts\pip.exe install filemagic
Downloading/unpacking filemagic
Downloading filemagic-1.6.tar.gz
Running setup.py (path:c:\users\vaclav~1.vas\appdata\local\temp\pip_build_vaclav.vasenka\filemagic\setup.py) egg_info for package filemagic
Installing collected packages: filemagic
Running setup.py install for filemagic
Successfully installed filemagic
Cleaning up...
I've created test.py with content:
import magic
print "test"
And when I run the file import throws exception:
Traceback (most recent call last):
File "E:\sand\test.py", line 2, in <module>
import magic
File "C:\Python27\lib\site-packages\magic\__init__.py", line 18, in <module>
from magic.identify import Magic, MagicError
File "C:\Python27\lib\site-packages\magic\identify.py", line 16, in <module>
from magic import api
File "C:\Python27\lib\site-packages\magic\api.py", line 22, in <module>
raise ImportError('Unable to find magic library')
ImportError: Unable to find magic library
Is the filemagic corrupted ? Is this module even working ?
From the PYPI Description (emphasis mine)
A Python API for libmagic, the library behind the Unix file command
and
libmagic is the library that commonly supports the file command on
Unix system, other than Max OSX which has its own implementation. The
library handles the loading of database files that describe the magic
numbers used to identify various file types, as well as the associated
mime types. The library also handles character set detections.
You cannot use this on Windows, as you are attempting.
You can attempt to use the mimetypes module in the standard library (mimetypes.guess_type would be what to look at).
I faced the same problem with docker containers with Alpine Linux image:
It seems like in Alpine Linux the library search doesn't work, hence it fails to find 'libmagic.so.1' which is required for the working of magic library( dependency filemagic and libmagic).
Workaround:
Use Python slim instead of Alpine Linux
mime, mimetypes are the other python libraries which can be used (the only downside to these two libraries is, that they find the mime type based on file extension and not file headers.

Python Subversion wrapper library

In Subversion's documentation there's an example of using Subversion from Python
#!/usr/bin/python
import svn.fs, svn.core, svn.repos
def crawl_filesystem_dir(root, directory):
"""Recursively crawl DIRECTORY under ROOT in the filesystem, and return a list of all the paths at or below DIRECTORY."""
# Get the directory entries for DIRECTORY.
entries = svn.fs.svn_fs_dir_entries(root, directory)
When I run this code I get an import error:
$ python crawl.py
Traceback (most recent call last):
File "crawl.py", line 7, in <module>
import svn.fs, svn.core, svn.repos
ImportError: No module named svn.fs
This means I'm missing the library svn. I tried to install the package, but the Python package manager can't find it.
$ pip install svn
Downloading/unpacking svn
Could not find any downloads that satisfy the requirement svn
No distributions at all found for svn
So, how do I install this library?
The library referred to by this documentation is the SWIG-based wrappers which build and ship with Subversion itself. Thus -- if your operating system's package is subversion, look for a subversion-python package to ship alongside it. If you're building subversion from source, you'll want to use the --with-python configure option for the bindings to be built alongside.
An alternative (with a quite different API) is the 3rd-party wrapper pysvn. These are better-documented and are easier to use, but are also less efficient in terms of runtime performance (they don't implement all the connection reuse capabilities and such of the underdocumented "official" bindings).
You need to install subversion-python in order to be able to import the classes.
In my case (Fedora)
sudo yum install subversion-python
Apt-get should have more or less the same

How does one install pyzmq 2.1.10 for python2.6 on window xp win32?

I'm trying to install pyzmq and there seems to be no working windows binarys for py2.6 at pipy
Also there are none at https://github.com/zeromq/pyzmq/downloads. They do have a msi for pyzmq 2.1.4 but that one also does not seem to work.
Tried
easy_install-2.6 pyzmq
which ties to install pyzmq 2.1.10 but fails with the error
Fatal: ZMQ directory must be specified on Windows via setup.cfg or 'python setup.py configure --zmq=/path/to/zeromq2'
error: Setup script exited with 1
then tied
easy_install-2.6 pyzmq configure --zmq=C:\home\installed_applications\ZeroMQ_2.1.10
and get the same error so I decide to download pyzmq-2.1.10
I cd into C:\Python26\Lib\site-packages\pyzmq-2.1.10
and run
python setup.py configure --zmq==C:\home\installed_applications\ZeroMQ_2.1.10
and I get
running configure
Configure: Autodetecting ZMQ settings...
Custom ZMQ dir: C:\home\installed_applications\ZeroMQ_2.1.10
Fatal:
Failed to run ZMQ test program. Please check to make sure:
* You have a C compiler installed
* A development version of Python is installed (including header files)
* A development version of ZMQ >= 2.1.4 is installed (including header files)
* If ZMQ is not in a default location, supply the argument --zmq=<path>
* If you did recently install ZMQ to a default location,
try rebuilding the ld cache with `sudo ldconfig`
or specify zmq's location with `--zmq=/usr/local`
I also tried building it using the instructions zeromq gives here
http://www.zeromq.org/docs:windows-installations
but there seems to be gaps either in me knowing how to use the ruby installer or in the instructions.
Lastly I tried using a windows installer from
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyzmq
but that gave me the following error
import zmq
Traceback (most recent call last):
File "", line 1, in
File "C:\Python26\Lib\site-packages\pyzmq-2.1.10\zmq__init__.py", line 35, in
from zmq.utils import initthreads # initialize threads
ImportError: cannot import name initthreads
I also tired installing via the link at the very bottom of http://www.zeromq.org/docs:windows-installations
linking to http://miru.hk/archive/ZeroMQ-2.1.10-win32.exe but I also get an error message.
Has anyone got this to work lib to work with python2.6? python2.7 seems to have no issues.
Actually even if you use the win installers from https://github.com/zeromq/pyzmq/downloads for python2.7 for zmq 2.1.10 you get the error IPython.zmq requires pyzmq >= 2.1.4, but you have 2.1.10. Clearly a bug in the checking of the version. The older version 2.1.7 works seems to work because the 7 passes the check since its one digit long I'm guessing.

Categories

Resources