Is it possible to use P4Python API with IronPython? - python

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.

Related

How do i upload tinkergraph into python/gremlin?

I am trying to use gremlin in python. I imported the following:
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.structure.graph import Graph
from gremlin_python import statics
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.process.traversal import *
import asyncio
statics.load_statics(globals())
When i run this:
graph = TinkerGraph.open()
graph.io(graphml()).readGraph('air-routes.graphml')
i get the following error:
NameError: name 'TinkerGraph' is not defined
How do i resolve this?
There is no TinkerGraph in Python. In gremlin-python you only get a reference to a graph remotely on a server and that might be a TinkerGraph or something else. If you want to load data that way, you must issue that command as a script through a Client instance:
client = Client('ws://localhost:45940/gremlin', 'g')
client.submit("graph.io(graphml()).readGraph('air-routes.graphml');[]").all().result()
where "graph" in that script is a Graph instance that already exists on the server (and is likely empty). If you're using Gremlin Server, you might consider doing that loading separately as part of Gremlin Server startup as well and then just using gremlin-python to query that data. That would probably be best in this example as the data would just be present when the server is started.
Note that in 3.4.0, we introduce the io() step which will be part of gremlin-python directly at which point you will be able to directly do:
g.io('air-routes.xml').read()
in native python and it will just work (again, the Graph instance must be defined remotely) though the file must be readable by the server.
Here's my working example in the Python shell for submitting a script, first with the tornado error and then without:
$ env/bin/python
Python 3.4.3 (default, Nov 28 2017, 16:41:13)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gremlin_python.driver.client import Client
>>> client = Client('ws://localhost:8182/gremlin', 'g')
>>> client.submit("g.V()").all().result()
Traceback (most recent call last):
File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/client.py", line 51, in __init__
from gremlin_python.driver.tornado.transport import (
File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/tornado/transport.py", line 19, in <module>
from tornado import ioloop, websocket
ImportError: No module named 'tornado'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/driver_remote_connection.py", line 45, in __init__
password=password)
File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/client.py", line 54, in __init__
raise Exception("Please install Tornado or pass"
Exception: Please install Tornado or passcustom transport factory
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()
$ env/bin/pip install tornado
Collecting tornado
Collecting backports-abc>=0.4 (from tornado)
Using cached https://files.pythonhosted.org/packages/7d/56/6f3ac1b816d0cd8994e83d0c4e55bc64567532f7dc543378bd87f81cebc7/backports_abc-0.5-py2.py3-none-any.whl
Installing collected packages: backports-abc, tornado
Successfully installed backports-abc-0.5 tornado-5.1.1
smallette#ubuntu:~/git/apache/incubator-tinkerpop/gremlin-python/target/python3$ env/bin/python
Python 3.4.3 (default, Nov 28 2017, 16:41:13)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gremlin_python import statics
>>> client = Client('ws://localhost:8182/gremlin', 'g')
>>> client.submit("g.V()").all().result()
[v[0]]

sympy import error in IronPython 2.7

I'm trying to use the sympy library in my python script, but I'm getting an error when I try to import it. How do I fix this?
The library you are using seems to make use of an internal API to get information of the current stack/live objects.
In order to provide the required information and interfaces you have to run IronPython with the -X:FullFrames argument.
Should you plan on hosting IronPython from C# this answer explains the necessary steps.
Instead of the previous situation/error
C:\Program Files (x86)\IronPython 2.7>ipy
IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.42000 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys._getframe(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '_getframe'
you will get the expected behavior
C:\Program Files (x86)\IronPython 2.7>ipy -X:FullFrames
IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.42000 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys._getframe(0)
<frame object at 0x000000000000002B>

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.

ImportError while importing winreg module of 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

"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.

Categories