ImportError while importing winreg module of python - python

I wanted to use winreg module of python for working with windows registry.
But when I try to import winreg module, it gives ImportError.
Python 2.4.3 (#1, Dec 11 2006, 11:39:03)
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import __winreg
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named __winreg
>>> import _winreg
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named _winreg
Do I need to install this module separately ?
Any suggestions would be useful.

It can't work on Linux.
_winreg - Windows registry access
Availability: Windows.
New in version 2.0. These functions expose the Windows registry API to
Python. Instead of using an integer as the registry handle, a handle
object is used to ensure that the handles are closed correctly, even
if the programmer neglects to explicitly close them.
This module exposes a very low-level interface to the Windows
registry; it is expected that in the future a new winreg module will
be created offering a higher-level interface to the registry API.
source: http://docs.python.org/release/2.1.2/lib/module--winreg.html

It looks like you're trying to import a windows only module on a *nix platform (RedHat is not Windows).
_winreg – Windows registry access
Platforms: Windows

Related

pypy5.6 install confluent_kafka cause: undefined symbol PyUnicode_FromFormat Error

When install confluent_kafka on pypy5.6, its has an error of : undefined symbol PyUnicode_FromFormat Error, i dont know how its happend ?
the os is: CentOs5.6
the full error output is :
Python 2.7.12 (aff251e543859ce4508159dd9f1a82a2f553de00, Nov 12 2016, 08:50:18)
[PyPy 5.6.0 with GCC 6.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import confluent_kafka
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/pypy/site-packages/confluent_kafka/init.py", line 2, in
from .cimpl import *
ImportError: unable to load extension module '/usr/local/pypy/site-packages/confluent_kafka/cimpl.pypy-41.so': /usr/local/pypy/site-packages/confluent_kafka/cimpl.pypy-41.so: undefined symbol: PyUnicode_FromFormat
How can I resolve this issue?
PyUnicode_FromFormat is not implemented so far inside PyPy. We'll get to it at some point (maybe soon if you have an example that requires it). You can also contribute it directly, if you want to get involved.
FWIW it is implemented in the py3.5 branch implementing Python 3.5, but not in trunk (supporting Python 2.7). Trunk only implements PyString_FromFormat. It's mostly a matter of back-porting the implementation, and "downgrading" the C code: in py3.5 it comes from CPython 3.5, so for trunk we'd need the same C code from CPython 2.7 instead.

Python3 on Ubuntu giving errors on help() command

I used help() in the python3 shell on Ubuntu 14.04
I got this output
Please help , don't know whats wrong.
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/_sitebuiltins.py", line 98, in __call__
import pydoc
File "/usr/lib/python3.4/pydoc.py", line 65, in <module>
import platform
File "/home/omega/platform.py", line 2, in <module>
print("System : ",platform.uname().system)
AttributeError: 'module' object has no attribute 'uname'
>>>
The problem is that platform is the name of a stdlib module, which help uses. By creating a module of your own with the same name that occurs before the stdlib in your sys.path, you're preventing Python from using the standard one.
The fact that your own platform module tries to use the stdlib module of the same name just compounds the problem. That isn't going to work; your import platform inside that module is just importing itself.
The solution is to not collide names like this. Look at the list of the standard modules, and don't create anything with the same name as any of them if you want to use features from that module, directly or indirectly.
In other words: Rename your platform.py to something else, or put it inside a package.
File "/home/omega/platform.py", line 2, in <module>
print("System : ",platform.uname().system)
This is the problem, go to platform.py and fix it, it will be ok. It says, platform has not any method called uname you probably misstyped.

Unable to import RRDtool in Python

I am trying to import RRDtool into Python as I want to access an RRD database using Python, but when I am trying to import rrdtool I am getting the following error.
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('/opt/rrdtool-1.4.5/bin')
>>> import rrdtool
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named rrdtool
My RRDtool is located in /opt/rrdtool-1.4.5/bin.
Well, the problem is solved just by executing the following command.
sudo apt-get install python-rrd
You probably need py-rrdtool, which you could get directly from the site or your package manager.
It is unlikely that Python modules are located inside a 'bin' folder. And importing files from some configured path requires that the referred path is a proper Python package. It means it must contain an __init__.py file.
You could use the RRDtool documentation for inspiration (man rrdpyton). Something
along the lines of
import sys
sys.path.append('/path/to/rrdtool/lib/python2.6/site-packages/')
import rrdtool
should do the trick.

"from _json import..." - python

I am inspecting the JSON module of python 3.1, and am currently in /Lib/json/scanner.py. At the top of the file is the following line:
from _json import make_scanner as c_make_scanner
There are five .py files in the module's directory: __init__ (two leading and trailing underscores, it's formatting as bold), decoder, encoder, scanner and tool. There is no file called "json".
My question is: when doing the import, where exactly is "make_scanner" coming from?
Yes, I am very new to Python!
It's coming from a C-compiled _json.pyd (or _json.so, etc, etc, depending on the platform) that lives elsewhere on the sys.path. You can always find out where that is in your specific Python installation by importing the module yourself and looking at its __file__, e.g.:
>>> import _json
>>> _json.__file__
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/_json.so'
As you see, in my installation of Python 2.6, _json comes from the lib-dynload subdirectory of lib/python2.6, and the extension used on this platform is .so.
It may be coming from a file, or it may be built-in. On Windows, it appears to be built-in.
Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import _json
>>> _json.__file__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
and there is no _json.pyd or _json.dll in the offing.
If you want to see the source, having a binary file on your machine or not is irrelevant -- you'll need the SVN browser.

Is it possible to use P4Python API with IronPython?

Is it possible to use P4Python (the perforce python api) with IronPython? I'd like to use the python api because it seems much faster than using p4.net implementionat of a Perforce API but when I try to import p4 into IronPython I receive the following error.
IronPython 2.6.1 (2.6.10920.0) on .NET
4.0.30128.1 Type "help", "copyright", "credits" or "license" for more
information.
import P4 Traceback (most recent call last): File "", line 1,
in File "C:\Program
Files\IronPython 2.6 for .NET
4.0\lib\site-packages\P4.py", l ine 210, in ImportError: No
module named P4API
I guess P4API is CPython extension so it does not work in IronPython. In that case, try ironclad.

Categories