I'm new to Python, and I'm learning to write C extensions for Python under Windows. Following a tutorial, I successfully compiled my exmaple.dll file using Cygwin.
The dll file seems okay as I can import it and the function of it also works.
Note that this is done using the Python of Cygwin. However, I can't use this dll under my own Python (not the one in Cygwin). I have copied the dll file to the Python search path, though. ImportError was raised.
I'm thinking, is it because the versions of two Python are different?
Cygwin comes with Python 2.7.5, while I use 2.7.6.
(Posted on behalf of the OP).
Finally I decided to use Ubuntu, it's simpler to accomplish this.
Related
I am using a VS Code (Linux Mint) plug-in for Python that allows me to choose between different interpreters.
When I run my file with Python 3.8, I get an error saying that it can't find pandas I am trying to use, but when I switch the interpreter to Python 3.6 there is no issue finding pandas.
What's going on?
The module might not be updated for Python 3.8. Search up the module's name from GitHub or where it can be imported from to see what versions they support.
That module isn't installed for Python 3.8, simple as that. Different versions of Python have different libraries (listed under sys.path) on Debian-based distros.
Without knowing which module, it's hard to say much else, like whether it even supports 3.8, but to install it, you might be able to use apt or pip.
C program is compiled and converted into .dll using cygwin compiler.In python scripting it can be loaded using ctypes and call the functions successfully.But I import that python scripting as libraray into Robot Framework Automation tool,it cant load that .dll file and the test case also failed.
is the cygwin created dll file not be supported by RTF?
Can anyone suggest any other method for that?
Given our discussion in the comments. You can't mix and match like this. The format that Cygwin builds a DLL in is different that the format Windows expects a DLL in. You need to build and run all in one environment.
I'm trying to use PyUNO as a method to convert different document formats (doc, wordperfect, html, etc) to PDF from within my Django server. I'm having a heck of a time getting import uno to work. It seems to fail when doing import pyuno, with a message of ImportError: DLL Load Failed: The specified module could not be found.
The only way I can get this to work is to use the Python 2.6 that came with OpenOffice, but I really want to use my other 2.6 installation. The docs for PyUNO are all for Python 2.2, and reputed to be out-of-date.
I'm guessing that some (or all) of the following files need to be copied from the OpenOffice directory to my site-packages directory (or some subdirectory thereof):
pythonloader.py
pythonloader.uno.ull
pythonloader.uno.ini
pythonscript.py
pyuno.pyd
Has anyone had any success getting this to work?
This is on Windows.
For simply conversions, you needn't reinvent the wheel. Look at unoconv: http://dag.wieers.com/home-made/unoconv/
'Import uno' will automatically work IF the python interpreter was bundled with OpenOffice, or in some Linux systems where the packagers have done a lot of work for you already.
Alternative 1: For other Python installs on Win32 systems, you need to import three environment variables and add one item to your Pythonpath. The detailed tutorial is at http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=36370&p=166783
The three environment variables you must get FROM your OO-installed-Python and add TO your other install of Python are:
(Using Python 2.6 and OO 3.1.2)
os.environ['URE_BOOTSTRAP'] = 'vnd.sun.star.pathname:c:\Program Files\OpenOffice.org 3\program\fundamental.ini'
os.environ['UNO_PATH'] = 'c:\Program Files\OpenOffice.org 3\program\'
os.environ['PATH'].append('c:\Program Files\OpenOffice.org 3\URE\bin;c:\Program Files\OpenOffice.org 3\Basis\program;')
The pythonpath item you must add TO your other install of Python is the location of the uno module:
sys.path.append('C:\Program Files\OpenOffice.org 3\Basis\program')
Now you can simply 'import uno'.
Pyuno is only compatible with a similar version of Python. Since OO 3.1 bundles Python 2.6.1, that pyuno is only compatible with another Python 2.6. Attempting to import uno into a different version of Python will cause a runtime error. But there's a way around that in Alternative 2.
Alternative 2: For other Python installs on WIN32 systems, you can ignore the Python-UNO bridge completely and use the Python-COM bridge instead. You must install one new module, and the API has a few differences, but you can use ANY version of Python, including Python3.
Install the pywin32module to get COM access: http://sourceforge.net/projects/pywin32/
Discussion on the API differences: http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=36608&p=168179
I also need an answer to this. I'm using windows XP and have a system where I extract data from a SQL server DB and insert it into template excel files. I DON'T want to add macro's etc to the OpenOffice. but I want to use the service to produce these files.
However, the only way I seem to be able to import the uno modude is to use the python.exe from the openoffice directory. even then I can't associate this exec with the py files in my system for some reason, thus I have to put in full path names each and every time.
I know that in Linux, the Pyuno module is an addon and can be used in normal python, but in windows this doesn't seem to be the case. I have listed all the relevant path details from the python exec under openoffice and duplicated them in python 2.7, but pyuno still fails with unable to find DDL with no reference to what DDL.
I think the answer is "this is not possible." From other reading on the web, it appears that the stdlib used to compile/link the python executable from python.org is different from the stdlib used to compile/link the python.exe distributed with OpenOffice.org. I don't know why, and I'm still confused by the fact that both pythons give me the same startup messages. So I could be completely on the wrong track here.
How do I make a DLL (.NET) written in python code (IronPython)?
You cannot create a standard .NET .dll from IronPython code (.dll that can be used directly from C# or VB).
pyc.py produces .dll that can be used only by IronPython - check such .dll with Reflector and you will understand why.
You can probably use ironpycompiler, using examples in http://pythonhosted.org//ironpycompiler/html-en/command-line.html. It requires installations of both IronPython and of CPython (the regular Python).
You can use the script at C:\Program Files\[IronPython Program Directory]\Tools\Scripts.
I have a Python module with nothing but regular global functions. I need to call it from another business-domain scripting environment that can only call out to C DLLs. Is there anyway to build my Python modules so that to other code it can be called like a standard C function that's exported from a DLL? This is for a Windows environment. I'm aware of IronPython, but as far as I know it can only build .NET Assemblies, which are not callable as C DLL functions.
Take a look at this Codeproject article. One way would be wrap your python functions in a C dll and expose this to the callee.
COM is a binary protocol to solve this issue. But you will have to wrap this python dll in a COM wrapper. And add some code on the calling side as well.
The standard solution is to embed the Python interpreter (which is already a C DLL) in your application.
https://docs.python.org/extending/windows.html#using-dlls-in-practice
http://docs.python.org/extending/embedding.html
Py2exe can generate COM dlls from python code, by compiling and embedding python code + interpreter. It does not, AFAIK, support regular DLLs yet. For that, see dirkgently's answer about embedding python yourself.