DNP3 and Python

2,158 views
Skip to first unread message

Nicola Zanella

unread,
Feb 22, 2012, 4:55:35 AM2/22/12
to open-dnp3
Hi,
I tried the java bingind and I wonder if you are planning to
provide the same for Python.
Differences between them should be minimal but unfortunately I cannot
create a python version of your ruby script for java...

Thanks
Nicholas

Christopher Verges

unread,
Feb 22, 2012, 12:15:41 PM2/22/12
to open...@googlegroups.com
Hi Nicholas,

I don't mind giving it a try, but before I began, it sounds like you've already attempted something.  So we can learn and not repeat steps, what have you tried?

Chris

Nicola Zanella

unread,
Feb 22, 2012, 4:54:00 PM2/22/12
to open...@googlegroups.com
Hi Chris, I've tried to
copy from the java binding, removing the jni section, and then to compile
the "i" file with swig (manually).

I got many errors while trying to link and create the library, probably because I
didn't do that with rake but following swig help

I'm sorry, this doesn't help you very much :-)

Nicholas

2012/2/22 Christopher Verges <chris....@gmail.com>

Christopher Verges

unread,
Feb 22, 2012, 5:33:04 PM2/22/12
to open...@googlegroups.com
Hi Nicholas,

I've just started testing our Java bindings and am finding something missing, too.  It may be related.  Let me look into it further and get back to you.

And no worries, it did help!  At least in showing that the two problems are most likely related.

Chris

Christopher Verges

unread,
Feb 23, 2012, 3:59:02 AM2/23/12
to open...@googlegroups.com
Hi Nicholas and Adam,

I've refactored the autotools build to create a single shared library, libopendnp3.  The merge request is added: https://github.com/gec/dnp3/pull/11.

I found a reference that discusses how to build a Python swig module using autotools: http://realmike.org/blog/2010/07/18/building-swig-python-extensions-on-gnulinux/.  I'll start to play further with this.

Chris

Christopher Verges

unread,
Feb 24, 2012, 4:19:00 AM2/24/12
to open...@googlegroups.com
Hi Nicholas and Adam,

I made a few additional changes to the existing pull request since it hasn't been merged yet.  These fully fix the linking issues to the boost libraries used.  The Java version of OpenDNP3 as built using autotools is now verified to work properly.

Nicholas, I would recommend pulling this branch and attempting your Python port.  You should no longer run into any "unresolved symbols" issues.  Definitely let us know if you run into any other kinds of issues.

Thanks,
Chris

Christopher Verges

unread,
Feb 25, 2012, 1:46:38 AM2/25/12
to open...@googlegroups.com
Hi Nicholas,

I think I got the Python bindings working.  Changeset is at https://github.com/cverges/dnp3/commit/6ff63f5f608aa1dd604f73e1e839879322d21719.

Here's the 10-second guide to get it working under Ubuntu 11.10.  (The README file has been updated with additional details.)

autoreconf -f -i
./configure --with-python
make
sudo make install

python
> import pyopendnp3

At that point, have fun!  Let me know if it works for you.

Chris

Christopher Verges

unread,
Feb 25, 2012, 1:49:30 AM2/25/12
to open...@googlegroups.com
Oh, proof that it's working:

$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyopendnp3 import *
>>> a = Analog()
>>> print a
<pyopendnp3.Analog; proxy of <Swig Object of type 'apl::Analog *' at 0x1978bd0> >
>>> 

Chris

Nicola Zanella

unread,
Feb 25, 2012, 7:18:43 PM2/25/12
to open...@googlegroups.com
Hi Chris, thank you so much for your interest!

I tried your pull request, and pretty all went good; I can't understand why, but python compilation
doesn't work...

I installed, via aptitude, both python2.6-dev and python2.7-dev (and all the other dependencies) but this is what I got in the last step:

zampa@winzoz:~/dnp3$ make
make  all-am
make[1]: ingresso nella directory "/home/zampa/dnp3"
/bin/bash ./libtool  --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I.    -pthread -I/usr/include -DBOOST_TEST_DYN_LINK -DBOOST_ASIO_ENABLE_CANCELIO -DBOOST_REGEX_NO_LIB -g -O2 -MT DNP3Java/_pyopendnp3_la-PythonDNP3.lo -MD -MP -MF DNP3Java/.deps/_pyopendnp3_la-PythonDNP3.Tpo -c -o DNP3Java/_pyopendnp3_la-PythonDNP3.lo `test -f 'DNP3Java/PythonDNP3.cpp' || echo '/home/zampa/dnp3/'`DNP3Java/PythonDNP3.cpp
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -pthread -I/usr/include -DBOOST_TEST_DYN_LINK -DBOOST_ASIO_ENABLE_CANCELIO -DBOOST_REGEX_NO_LIB -g -O2 -MT DNP3Java/_pyopendnp3_la-PythonDNP3.lo -MD -MP -MF DNP3Java/.deps/_pyopendnp3_la-PythonDNP3.Tpo -c DNP3Java/PythonDNP3.cpp  -fPIC -DPIC -o DNP3Java/.libs/_pyopendnp3_la-PythonDNP3.o
DNP3Java/PythonDNP3.cpp:150:20: fatal error: Python.h: No such file or directory
compilation terminated.
make[1]: *** [DNP3Java/_pyopendnp3_la-PythonDNP3.lo] Errore 1
make[1]: uscita dalla directory "/home/zampa/dnp3"
make: *** [all] Errore 2


so it seems that it doesn't find Python.h header, but

zampa@winzoz:~/dnp3$ locate Python.h
/usr/include/python2.7/Python.h


Obviously, I followed your guide in the last email, is there any other option I need to use?

Thanks again
Nicholas


2012/2/25 Christopher Verges <chris....@gmail.com>

Chris Verges

unread,
Feb 25, 2012, 7:26:02 PM2/25/12
to open...@googlegroups.com, open...@googlegroups.com
Try this in the configure line:

configure --with-python=/usr/include/python2.7

This should tell g++ where to find the headers.

Chris


Jonathan Yu

unread,
Feb 25, 2012, 10:26:16 PM2/25/12
to open...@googlegroups.com
Shouldn't the ./configure script be able to find a reasonable default? (e.g. looking for any path matching /usr/include/python*)

In general, I think it's a Bad Thing(tm) when you ask your user to pass any arguments to ./configure that could be autodetected

Chris Verges

unread,
Feb 25, 2012, 10:56:14 PM2/25/12
to open...@googlegroups.com, open...@googlegroups.com
You get what you pay for.  :-)

Prior to 2 days ago, we had no mechanism to build a set of python wrappers.  I am sure the code will mature to be more refined -- in fact, I would love help in doing so!  Feel free to submit enhancements.

Chris 


Christopher Verges

unread,
Feb 26, 2012, 12:24:39 AM2/26/12
to open...@googlegroups.com
Change made:


Nicholas, you should be able to git pull and then autoreconf/configure/make again to have this work properly.

Chris

Nicola Zanella

unread,
Feb 27, 2012, 5:52:16 AM2/27/12
to open...@googlegroups.com
Hi Christofer, I pulled your last commit, and compiltation now is working fine, thanks.

But, I get an error when I try to install the library.
The error string is in italian, but it says something like "there's no rule to generate target pyopendnp3.py"

What I see in my disk is that the folder name and the .so name are different

nzanella@ESP1182:~/Scrivania/dnp3$ ll /usr/lib/python2.7/dist-packages/opendnp3
totale 9124
drwxr-xr-x   2 root root    4096 2012-02-27 11:33 ./
drwxr-xr-x 103 root root   12288 2012-02-27 11:33 ../
-rw-r--r--   1 root root 5727800 2012-02-27 11:33 _pyopendnp3.a
-rwxr-xr-x   1 root root    1141 2012-02-27 11:33 _pyopendnp3.la*
lrwxrwxrwx   1 root root      20 2012-02-27 11:33 _pyopendnp3.so -> _pyopendnp3.so.0.0.0*
lrwxrwxrwx   1 root root      20 2012-02-27 11:33 _pyopendnp3.so.0 -> _pyopendnp3.so.0.0.0*
-rwxr-xr-x   1 root root 3588208 2012-02-27 11:33 _pyopendnp3.so.0.0.0*


If i create a folder with above .so and pyopendnp3.py file (located in DNP3Java folder) it works, both with python2.6 and python2.7

nzanella@ESP1182:~/Scrivania/pyopendnp3$ python
Python 2.7.2+ (default, Oct  4 2011, 20:03:08)
[GCC 4.6.1] on linux2

Type "help", "copyright", "credits" or "license" for more information.
>>> from pyopendnp3 import *
>>> a = Analog()
>>> a
<pyopendnp3.Analog; proxy of <Swig Object of type 'apl::Analog *' at 0xb72baa10> >


So probably it's just a mispelling link somewhere :-)

Thank you again
Nicholas

Below install error

nzanella@ESP1182:~/Scrivania/dnp3$ sudo make install
[sudo] password for nzanella:
make[1]: ingresso nella directory "/home/nzanella/Scrivania/dnp3"
test -z "/usr/lib" || /bin/mkdir -p "/usr/lib"
 /bin/bash ./libtool   --mode=install /usr/bin/install -c   libopendnp3.la '/usr/lib'
libtool: install: /usr/bin/install -c .libs/libopendnp3.so.0.0.0 /usr/lib/libopendnp3.so.0.0.0
libtool: install: (cd /usr/lib && { ln -s -f libopendnp3.so.0.0.0 libopendnp3.so.0 || { rm -f libopendnp3.so.0 && ln -s libopendnp3.so.0.0.0 libopendnp3.so.0; }; })
libtool: install: (cd /usr/lib && { ln -s -f libopendnp3.so.0.0.0 libopendnp3.so || { rm -f libopendnp3.so && ln -s libopendnp3.so.0.0.0 libopendnp3.so; }; })
libtool: install: /usr/bin/install -c .libs/libopendnp3.lai /usr/lib/libopendnp3.la
libtool: install: /usr/bin/install -c .libs/libopendnp3.a /usr/lib/libopendnp3.a
libtool: install: chmod 644 /usr/lib/libopendnp3.a
libtool: install: ranlib /usr/lib/libopendnp3.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/sbin" ldconfig -n /usr/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/bin" || /bin/mkdir -p "/usr/bin"
  /bin/bash ./libtool   --mode=install /usr/bin/install -c testset '/usr/bin'
libtool: install: /usr/bin/install -c .libs/testset /usr/bin/testset
test -z "/usr/lib/python2.7/dist-packages/opendnp3" || /bin/mkdir -p "/usr/lib/python2.7/dist-packages/opendnp3"
 /bin/bash ./libtool   --mode=install /usr/bin/install -c   _pyopendnp3.la '/usr/lib/python2.7/dist-packages/opendnp3'
libtool: install: warning: relinking `_pyopendnp3.la'
libtool: install: (cd /home/nzanella/Scrivania/dnp3; /bin/bash /home/nzanella/Scrivania/dnp3/libtool  --tag CXX --mode=relink g++ -pthread -I/usr/include -DBOOST_TEST_DYN_LINK -DBOOST_ASIO_ENABLE_CANCELIO -DBOOST_REGEX_NO_LIB -g -O2 -module -L/usr/lib -lpython2.7 -o _pyopendnp3.la -rpath /usr/lib/python2.7/dist-packages/opendnp3 DNP3Java/_pyopendnp3_la-PythonDNP3.lo libopendnp3.la -lpython2.7 -lpython2.7 -lpython2.7 -lpthread -lc )
libtool: relink: g++  -fPIC -DPIC -shared -nostdlib /usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crti.o /usr/lib/gcc/i686-linux-gnu/4.6.1/crtbeginS.o  DNP3Java/.libs/_pyopendnp3_la-PythonDNP3.o   -L/usr/lib -lopendnp3 -lpython2.7 -lpthread -L/usr/lib/gcc/i686-linux-gnu/4.6.1 -L/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu -L/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib -L/lib/i386-linux-gnu -L/lib/../lib -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/i686-linux-gnu/4.6.1/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/i686-linux-gnu/4.6.1/crtendS.o /usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crtn.o  -pthread -O2   -pthread -Wl,-soname -Wl,_pyopendnp3.so.0 -o .libs/_pyopendnp3.so.0.0.0
libtool: install: /usr/bin/install -c .libs/_pyopendnp3.so.0.0.0T /usr/lib/python2.7/dist-packages/opendnp3/_pyopendnp3.so.0.0.0
libtool: install: (cd /usr/lib/python2.7/dist-packages/opendnp3 && { ln -s -f _pyopendnp3.so.0.0.0 _pyopendnp3.so.0 || { rm -f _pyopendnp3.so.0 && ln -s _pyopendnp3.so.0.0.0 _pyopendnp3.so.0; }; })
libtool: install: (cd /usr/lib/python2.7/dist-packages/opendnp3 && { ln -s -f _pyopendnp3.so.0.0.0 _pyopendnp3.so || { rm -f _pyopendnp3.so && ln -s _pyopendnp3.so.0.0.0 _pyopendnp3.so; }; })
libtool: install: /usr/bin/install -c .libs/_pyopendnp3.lai /usr/lib/python2.7/dist-packages/opendnp3/_pyopendnp3.la
libtool: install: /usr/bin/install -c .libs/_pyopendnp3.a /usr/lib/python2.7/dist-packages/opendnp3/_pyopendnp3.a
libtool: install: chmod 644 /usr/lib/python2.7/dist-packages/opendnp3/_pyopendnp3.a
libtool: install: ranlib /usr/lib/python2.7/dist-packages/opendnp3/_pyopendnp3.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/sbin" ldconfig -n /usr/lib/python2.7/dist-packages/opendnp3
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/lib/python2.7/dist-packages/opendnp3

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/include/opendnp3" || /bin/mkdir -p "/usr/include/opendnp3"
/bin/mkdir -p '/usr/include/opendnp3/APL'
 /usr/bin/install -c -m 644  APL/ASIOSerialHelpers.h APL/AsyncLayerInterfaces.h APL/AsyncTaskBase.h APL/AsyncTaskContinuous.h APL/AsyncTaskGroup.h APL/AsyncTaskInterfaces.h APL/AsyncTaskNonPeriodic.h APL/AsyncTaskPeriodic.h APL/AsyncTaskScheduler.h APL/BaseDataTypes.h APL/BoundNotifier.h APL/CachedLogVariable.h APL/ChangeBuffer.h APL/CommandInterfaces.h APL/CommandManager.h APL/CommandQueue.h APL/CommandResponseQueue.h APL/CommandTypes.h APL/Configure.h APL/CopyableBuffer.h APL/CRC.h APL/DataInterfaces.h APL/DataTypes.h APL/DeleteAny.h APL/EventLockBase.h APL/EventLock.h APL/EventSet.h APL/Exception.h APL/FlexibleDataObserver.h APL/Function.h APL/GetKeys.h APL/IEventLock.h APL/IHandlerAsync.h APL/INotifier.h APL/IOService.h APL/IOServiceThread.h APL/IPhysicalLayerAsync.h APL/IPhysicalLayerObserver.h APL/IPhysicalLayerSource.h APL/ISubject.h '/usr/include/opendnp3/APL'
/bin/mkdir -p '/usr/include/opendnp3/APL'
 /usr/bin/install -c -m 644  APL/ITimer.h APL/ITimerSource.h APL/ITimeSource.h APL/ITransactable.h APL/LockBase.h APL/LockBoost.h APL/Lock.h APL/LogBase.h APL/LogEntryCircularBuffer.h APL/LogEntry.h APL/Loggable.h APL/Logger.h APL/Log.h APL/LogToFile.h APL/LogToStdio.h APL/LogTypes.h APL/LogVar.h APL/LowerLayerToPhysAdapter.h APL/MetricBuffer.h APL/MultiplexingDataObserver.h APL/Notifier.h APL/PackingTemplates.h APL/PackingUnpacking.h APL/Parsing.h APL/PhysicalLayerAsyncASIO.h APL/PhysicalLayerAsyncBase.h APL/PhysicalLayerAsyncBaseTCP.h APL/PhysicalLayerAsyncSerial.h APL/PhysicalLayerAsyncTCPClient.h APL/PhysicalLayerAsyncTCPServer.h APL/PhysicalLayerFactory.h APL/PhysicalLayerFunctors.h APL/PhysicalLayerInstance.h APL/PhysicalLayerManager.h APL/PhysicalLayerMap.h APL/PhysicalLayerMonitor.h APL/PhysicalLayerMonitorStates.h APL/PhysicalLayerStates.h APL/PhysLayerSettings.h APL/PhysLoopback.h '/usr/include/opendnp3/APL'
/bin/mkdir -p '/usr/include/opendnp3/DNP3'
 /usr/bin/install -c -m 644  DNP3/AlwaysOpeningVtoRouter.h DNP3/APDUConstants.h DNP3/APDU.h DNP3/AppChannelStates.h DNP3/AppConfig.h DNP3/AppHeader.h DNP3/AppInterfaces.h DNP3/AppLayerChannel.h DNP3/AppLayer.h DNP3/AsyncStackManager.h DNP3/BufferSetTypes.h DNP3/BufferTypes.h DNP3/ClassCounter.h DNP3/ClassMask.h DNP3/ControlTasks.h DNP3/CTOHistory.h DNP3/Database.h DNP3/DatabaseInterfaces.h DNP3/DataPoll.h DNP3/DeviceTemplate.h DNP3/DeviceTemplateTypes.h DNP3/DNPCommandMaster.h DNP3/DNPConstants.h DNP3/DNPCrc.h DNP3/DNPDatabaseTypes.h DNP3/DNPExceptions.h DNP3/DNPFromStream.h DNP3/DNPToStream.h DNP3/EnhancedVto.h DNP3/EnhancedVtoRouter.h DNP3/EventBufferBase.h DNP3/EventBuffers.h DNP3/EventTypes.h DNP3/HeaderReadIterator.h DNP3/IFrameSink.h DNP3/ILinkContext.h DNP3/ILinkRouter.h DNP3/IndexedWriteIterator.h DNP3/IStackObserver.h DNP3/IVtoEventAcceptor.h '/usr/include/opendnp3/DNP3'
/bin/mkdir -p '/usr/include/opendnp3/DNP3'
 /usr/bin/install -c -m 644  DNP3/LinkChannel.h DNP3/LinkConfig.h DNP3/LinkFrame.h DNP3/LinkHeader.h DNP3/LinkLayerConstants.h DNP3/LinkLayer.h DNP3/LinkLayerReceiver.h DNP3/LinkLayerRouter.h DNP3/LinkReceiverStates.h DNP3/LinkRoute.h DNP3/MasterConfig.h DNP3/MasterConfigTypes.h DNP3/Master.h DNP3/MasterSchedule.h DNP3/MasterStackConfig.h DNP3/MasterStack.h DNP3/MasterStates.h DNP3/MasterTaskBase.h DNP3/ObjectHeader.h DNP3/ObjectInterfaces.h DNP3/ObjectReadIterator.h DNP3/Objects.h DNP3/ObjectWriteIterator.h DNP3/PointClass.h DNP3/PriLinkLayerStates.h DNP3/ResponseContext.h DNP3/ResponseLoader.h DNP3/SecLinkLayerStates.h DNP3/SlaveConfig.h DNP3/SlaveEventBuffer.h DNP3/Slave.h DNP3/SlaveResponseTypes.h DNP3/SlaveStackConfig.h DNP3/SlaveStack.h DNP3/SlaveStates.h DNP3/SolicitedChannel.h DNP3/Stack.h DNP3/StackManager.h DNP3/StartupTasks.h DNP3/TLS_Base.h '/usr/include/opendnp3/DNP3'
/bin/mkdir -p '/usr/include/opendnp3/APL'
 /usr/bin/install -c -m 644  APL/PostingNotifier.h APL/PostingNotifierSource.h APL/ProtocolUtil.h APL/QualityConverter.h APL/QualityMasks.h APL/QueueingFDO.h APL/Random.h APL/RandomizedBuffer.h APL/SerialTypes.h APL/ShiftableBuffer.h APL/Singleton.h APL/SubjectBase.h APL/SuspendTimerSource.h APL/SyncVar.h APL/Threadable.h APL/ThreadBase.h APL/ThreadBoost.h APL/Thread.h APL/TimeBase.h APL/TimeBoost.h APL/Timeout.h APL/TimerASIO.h APL/TimerSourceASIO.h APL/TimeSource.h APL/TimeTypes.h APL/TimingTools.h APL/ToHex.h APL/TrackingTaskGroup.h APL/Types.h APL/Uncopyable.h APL/Util.h '/usr/include/opendnp3/APL'
 /usr/bin/install -c -m 644  version.hpp '/usr/include/opendnp3/.'
/bin/mkdir -p '/usr/include/opendnp3/DNP3'
 /usr/bin/install -c -m 644  DNP3/TransportConstants.h DNP3/TransportLayer.h DNP3/TransportRx.h DNP3/TransportStates.h DNP3/TransportTx.h DNP3/UnsolicitedChannel.h DNP3/VtoConfig.h DNP3/VtoData.h DNP3/VtoDataInterface.h DNP3/VtoEventBufferAdapter.h DNP3/VtoReader.h DNP3/VtoRouter.h DNP3/VtoRouterManager.h DNP3/VtoRouterSettings.h DNP3/VtoTransmitTask.h DNP3/VtoWriter.h '/usr/include/opendnp3/DNP3'
make[1]: ***  Nessuna regola per generare l'obiettivo "pyopendnp3.py", necessario per "install-pkgpythonPYTHON".  Arresto.
make[1]: uscita dalla directory "/home/nzanella/Scrivania/dnp3"
make: *** [install-am] Errore 2




2012/2/26 Christopher Verges <chris....@gmail.com>

Christopher Verges

unread,
Feb 27, 2012, 3:03:56 PM2/27/12
to open...@googlegroups.com
Hi Nicola,

I ran into this same error during development.  Looks like I fixed it somehow, but not sure what I did.  I'll look into it further today.

Chris

Christopher Verges

unread,
Feb 27, 2012, 4:39:09 PM2/27/12
to open...@googlegroups.com
Bongiorno, Nichola!

After reading the make output in Italian, I felt inspired.  :-)  I found the source of the error and fixed it.  I had fixed it in my workspace by manually copying the file to the correct location, which is obviously a "bad thing" for others.  The new version of the Makefile.am should now work, so do a git pull and rebuild.


Chris

Nicola Zanella

unread,
Feb 28, 2012, 9:08:16 AM2/28/12
to open...@googlegroups.com
Hi, Chris, eheh yes I know, italian can be inspiring!
So, now compiling and installing works fine, but there's still something missing.

Now a folder named opendnp3 is created in the /usr/lib/python2.7/dist-packages folder, containing all the needed stuff but one file, called "__init__.py".
This is the strange way python handles packages; that file must be present, even if it is empty.

So now, you have two options:
1) create an empy "__init__.py" file. After running python and in order to use your library users must import code with a statement like
     "from opendnp3.pyopendnp3 import *"

2) create a "__init__.py" file, containing a line like "from pyopendnp3 import *" (you can specify which symbols export instead of *).
     This way, the users, after running python can do something like "from opendnp3 import *"

Your example in your previous email worked because you ran it in the same folder!

Hope this is helpful.

Thanks
Nicholas

2012/2/27 Christopher Verges <chris....@gmail.com>

Christopher Verges

unread,
Feb 28, 2012, 1:34:07 PM2/28/12
to open...@googlegroups.com
Good catch, I made a few modifications to install the __init__.py file using the second option you described.  Let me know how it works for you!

Chris

Nicola Zanella

unread,
Mar 1, 2012, 10:58:11 AM3/1/12
to open...@googlegroups.com
Hi Chris, yes now is working perfectly, thanks!

I have just another curiosity: i tried almost every option in configure, but I could not select python2.6 as target python.
I'm working on a Ubuntu 11.10, where python2.7 is the default.
The work-around I've found is to use virtualenv.

Can you help me with the right configure args?

Thanks again
Nicholas


2012/2/28 Christopher Verges <chris....@gmail.com>

Christopher Verges

unread,
Mar 1, 2012, 11:08:55 AM3/1/12
to open...@googlegroups.com
I think you just set --with-python=/usr/include/python2.6.  However, I haven't tried setting a specific Python version.  There may also be a way of using a site config override.  Give the --with-python a shot, and let me know.  I can dig into it further only if needed.

Chris

Nicola Zanella

unread,
Mar 7, 2012, 6:38:16 AM3/7/12
to open...@googlegroups.com
Hi Crhis,
    I tried that option (before writing my last email). My problem was not on the headers (CPPFLAGS), but on the "LIBS" flag (its value is "-lpython2.7 -lpthread -lc").

In any case, since with virtualenv it compiles good, IMHO there's no need to dig into it further.
Now I'm trying to use that wrapper; I started trying to port "SlaveDemo" app in python, but some used classes are not wrapped. Is it a good point to start with?

What I'm trying to do is to write a simple slave (the final step will be integrate it in a Twisted protocol)

NZ


2012/3/1 Christopher Verges <chris....@gmail.com>

Christopher Verges

unread,
Mar 7, 2012, 10:27:43 AM3/7/12
to open...@googlegroups.com
My guess from looking at the m4 helper script is that you can set your preferred Python version:


Try this instead:

./configure PYTHON_VERSION=2.6

Your idea to create a "SlaveDemo.py" sounds like a great one.  It'll certainly expose issues like missing class declarations.  If you're willing, this would be something that would be helpful to include in the repository, too, so others can use it as a "test" of their own compile process.

Chris

Nicola Zanella

unread,
Mar 7, 2012, 11:22:51 AM3/7/12
to open...@googlegroups.com
Yes, I will share with you my (working) python scripts.
So I'll post here missing declaration about SlaveDemo porting, but is there any other script I can try to port to understand (better) how the library works?

P.S. Neither "./configure PYTHON_VERSION=2.6" nor "./configure --with-python PYTHON_VERSION=2.6" seem to produce different output...

NZ

2012/3/7 Christopher Verges <chris....@gmail.com>
Reply all
Reply to author
Forward
0 new messages