I build python2.6.1 on laptop. Build was successful. After that I tried to run python using ./python and tried to import select module
>>>import select
>>>select.epoll()
<select.epoll object at 0xb76140d0>
After that I copied the python build folder to anther laptop and tried to run python
>>>import select
>>> select.epoll()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'epoll'
How to solve this problem
From the manual:
select.epoll([sizehint=-1])
(Only supported on Linux 2.5.44 and newer.)
Returns an edge polling object, which can be used as Edge or Level Triggered interface
for I/O events; see section Edge and Level Trigger Polling (epoll)
Objects below for the methods supported by epolling objects.
New in version 2.6.
And obviously distromakers can disable it in python build settings or so. It does depend on glibc only as far as I know. Also are you sure you are importing from the system select module, and not from your own module named by the same name? (check select.__file__; as a builtin module it should not have a file ;)
Related
I am trying to connect to rethink db(has a python driver) from my java app.
RethinkDB python install section https://www.rethinkdb.com/docs/install-drivers/python/ does not have a place to explicitly download the python modules. Because for me, I am trying to use jython to connect and it fails with following
code:
String s = "import rethinkdb as r\n" +
"r.connect('localhost', 28015).repl()\n" +
"r.table('tv_shows').insert({ 'name': 'Star Trek TNG' }).run()";
PyCode code = python.compile(s);
python.exec(code);
System.out.println("Done..");
Error:
Exception in thread "main" Traceback (most recent call last):
File "", line 1, in
ImportError: No module named rethinkdb
Any idea on where can I get the rethinkdb module explicitly and how I can made it available to my Java app ? (assume to out that into class path)
The currently released Python driver is always up on PyPi, and you can download it directly from: https://pypi.python.org/pypi/rethinkdb
I am not a Jython user, so I can best direct you to this question about modules: How can I install various Python libraries in Jython?
I should also note that an official Java driver was recently released: http://rethinkdb.com/blog/official-java-driver/
I am currently developing a Python module in C, and I cannot figure out how to make JEDI "see" my module.
I have set all docstrings in the C code and set every field in my setup.py, but when I edit the example.py file I use for testing and try to display documentation in vim using Shift+K, I get an error saying:
Exception, this shouldn't happen.
Traceback (most recent call last):
File "/home/beben/.vim/bundle/jedi-vim/jedi_vim.py", line 268, in show_documentation
definitions = script.goto_definitions()
File "/home/beben/.vim/bundle/jedi-vim/jedi/jedi/api/init.py", line 365, in goto_definitions
names = [s.name for s in definitions]
AttributeError: 'NoneType' object has no attribute 'name'
No documentation found for that.
After reading jedi's documentation, I understand that it uses Pydoc to gather information on the module.
When I run Pydoc mymodule, the documentation is correctly displayed.
Is there something more that I need to add to my code to be recognized by JEDI?
I am getting the following error when I try to run gtfs_realtime_pb2.py (the python code generated from running the gtfs-realtime.proto through google's protocol buffer):
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from google.protobuf import descriptor
ImportError: No module named 'google'
This is a link to the specific code I am having trouble with:
https://github.com/mattwigway/gtfsrdb
And the link to installing google's protocol buffer:
https://developers.google.com/protocol-buffers/
I am pretty certain I have install the buffer correctly, so why is it throwing up that it can't find this module?
Included in protocol buffer is descriptor.proto; python code for this proto should of been generated as part of the install process.
The protocol buffer you are using uses descriptor.proto so the directory where it resides needs to be included via the --proto_path= parameter (see Importing "google/protobuf/descriptor.proto" in java protocol buffers
For window systems, the install directory will be where you placed it; for *nix it will probably be answer taken from
/usr/include/descriptor.proto
or
/usr/local/include/descriptor.proto
i.e. for java you would do something like
protoc addressbookSD.proto --java_out=./ --proto_path=./ --proto_path=<protobuf-install-directory>/src
where <protobuf-install-directory> is the protocol buffers install directory. The key point is descriptor.proto is in
<protobuf-install-directory>\src\google\protobuf
Here is the script..
from distutils.core import setup, Extension
nmap = Extension('nmap',sources = ['nmap/nmap.py',
'nmap/__init__.py', 'nmap/example.py'])
from nmap import *
setup (
name = 'python-nmap',
version = nmap.__version__,
author = 'Alexandre Norman',
author_email = 'norman#xael.org',
license ='gpl-3.0.txt',
keywords="nmap, portscanner, network, sysadmin",)
... and i got this error:
Traceback (most recent call last):
File "C:\Python27\nmap.py", line 6, in <module>
from nmap import *
File "C:\Python27\nmap.py", line 17, in <module>
version = nmap.__version__,
AttributeError: Extension instance has no attribute '__version__'
There are a number of problems here.
Your nmap package isn't an extension, it's a pure-Python package; don't create an Extension object for it. Python extension are written in C or C++.
You're trying to access nmap.__version__, presumably because you defined that variable in nmap/__init__.py, but nmap here is that Extension object you created; it's trying to access the variable from the wrong thing.
Even if you remove the Extension object, you still wouldn't be able to access nmap.__version__, because you imported your package incorrectly; you meant to use import nmap.
You never actually pass your package to setup, so distutils won't know about it. There are a few examples of how to do that in the documentation.
The distutils documentation is pretty big, but it's a good idea to read through all of it at least once.
Okay i've been battling for this for 2 days, that usually means its something too simple to realize.
I have an embedded linux system which I cross compile on my ubuntu. When compiling python, sqlite3 is not on the list of modules that have not been able to be compiled.
But, the _sqlite3.so library is not in the same location as for example json.so and ctypes.so array.so...
in Python-2.6.6/build/lib.linux868-2.6/
The actual module with the init-functions etc is in the right place at :
in Python-2.6.6/modules and it can also be found on the target system.
Since the so-file was missing, i tried compiling it myself as a shared library using my arm-compiler. This did not work either.
Without manually compiled so-file:
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "rootfs/python/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
File "rootfs/python/lib/python2.6/sqlite3/dbapi2.py", line 27, in <module>
ImportError: /python/lib/python2.6/lib-dynload/_sqlite3.so: cannot open shared object file: No such file or directory
With the compiled shared library found at lib-dynloads:
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "rootfs/python/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
File "rootfs/python/lib/python2.6/sqlite3/dbapi2.py", line 27, in <module>
ImportError: dynamic module does not define init function (init_sqlite3)
Edit:
I was wondering if i had compiled the right library for sqlite3. As far as i now understand the _sqlite3.so is something the python builder makes and libsqlite3.so is the library it needs to build it? And libsqlite3.so is build from Sqlite3-source code. Am i mistaken here?
Anyone with more embedded Linux or Python experience have an idea what I am doing wrong here?
Try to compile and install sqlite3 first on your system, and compiler python later. Or just
easy_install pysqlite
Ok, figured this out. Somehow I did not manually compile the SO-file correctly. Got this to work like so:
First from setup.py , I added verbose debugging enabled for sqlite3 module. This added a printout that solved the problem:
skipping incompatible /usr/lib/libsqlite3.so
cannot find -sqlite3
That made me realize that the setup.py had chosen the first path where it found any module named sqlite3, ignoring it's architecture alltogether. Removing other search paths from the setup.py, but the one i had the ARM compiled library in, made it work. The _sqlite3.so was compiled nicely with all the other modules.