I am trying to use a specific natural language processor I found written in C# within my python application.
According to past SO posts, it seems as straightforward as:
import compile DLL file
call methods/classes of C# file from within python script with an enclosing wrapper
I have downloaded mono-develop and xamarin studio, have read the docs and attempted to "build" the C# program off of the .sln file, but have not observed any dll file being created
What step or doc am I missing?
https://msdn.microsoft.com/en-us/library/3707x96z.aspx
This link provided from MSDN shows how to compile DLLs. You use the developer command prompt which is installed when you install any version of Visual Studio.
From the link, here is an example format:
csc /target:library /out:MathLibrary.DLL Add.cs Mult.cs
You can build a solution with xbuild. check this out for more information: Microsoft.Build
or you can just download mono develop and open the solution with it and just click build. it would create the output dll file in the bin folder.
Related
I am working on a project to make a client program to connect CNC FANUC machine with a personal computer and collect several data using FOCAS library.
After downloading FOCAS library with several dll files and a focas library C# file, I tried to create a program to get the data from the machine based on the instruction of functions in FOCAS library (https://www.inventcom.net/fanuc-focas-library/general/fwlib32).
However, whenever I execute the program, I always face the error saying that "Unhandled exception. System.DllNotFoundException: Unable to load DLL 'FOCAS32.dll' or one of its dependencies(0x8007007E)".
I searched on the Google and stackoverflow questions list but nothing has been working.
Could you tell me how to solve this problem?
To elaborate the situation, I made a solution called "FanucCNCDataAcquisition.sln" by using Visual Studio 2019 and I stored two projects: one is FOCASLibrary which has a Focas32.cs for the library purpose and the other is DataAcquisition which has a program.cs for execution with the reference on the focas library. I downloaded several .dll files including FOCAS32.dll and those are not in the same directory with the solution so I am curious if the cause of the problem is based on the location of the files.
You need to reference the DLL within the solution, i'll show you in the steps below:
(My visual studio is in Portuguese but you can follow these steps with English)
First, you right-click on "References" and click "Add Reference"
In this window you are going to click "Search" and add your DLL manually
After that, all the classes and methods within this library will be available for you to use, you just go to the oficial documentation and look for code examples.
I tried the solution above but failed. Below are some other solutions I found.
The .dll files should be put in the debug folder, so you can just have a copy there.
Here's another solution in this article says that putting the .dll files under the C:\Windows\System32 folder should work, I tried and it did work.
I'm trying to use a Intel RealSense camera in a c# project.
While the example code seams to run just fine.
My own project in a different folder raises an exception.
Unable to load DLL
"realsense2:The specified module could not be found. (Exception from HRESULT:0x8007007E)."
I've now placed the realsense2.dll in lib folder and in debug folder.
I think its a unmanaged dll and the other "Intel.RealSense.dll" seams a .net interface dll . I placed both in lib and in debug folders I tried referencing the Intel.realsense.dll (.net api wrapper) in both locations (debug folder and in lib folder), but to no success.
From Intel forums I noted that sometimes the error gets raised when the CPU model isn't correct, but I kept those the same as the sample.
This must be some visual studio error (since the Intel example works).
But I miss where it goes wrong.
Step 1. Build the provided C++/C# samples using the instructions located in the main repo under /wrappers/csharp/readme.md
Generate the VS solution using cmake (run from librealsense root dir):
mkdir build
cd build
cmake .. -DBUILD_CSHARP_BINDINGS=ON -DBUILD_SHARED_LIBS=ON
The file realsense2.sln should be created in build folder, open the file with Visual Studio, C# examples and library will be available in the solution under Wrappers/csharp.
Both the native library and the .NET wrapper are built by default as part of the examples dependencies.
Step 2. Take a look at the working samples for reference. The default librealsense build on Windows is Debug/Win32 (For this config, built samples will be available at your_librealsense_dir/build/Debug)
In your C# project you need to have Intel.RealSense.dll added as a reference and copy realsense2.dll in your build directory ex: your_project_home/bin/x86/Debug
Note: Looking below, I think it's likely you have all these DLLs. Possibly you have a path issue. Check your EXE is running from the same folder the DLLs are in.
Here are the dependencies of realsense2.dll (x86) output by DUMPBIN:
These Windows ones:
KERNEL32.dll
USER32.dll
ole32.dll
OLEAUT32.dll
ADVAPI32.dll
SHLWAPI.dll
CFGMGR32.dll
SETUPAPI.dll
MF.dll
MFPlat.DLL
MFReadWrite.dll
WINUSB.DLL
And this VS 2017 one:
VCOMP140.DLL
Dependency Walker will tell you which ones you do or don't have.
reference Scrapy In Projects
This is what I do
1.create a new python project,create a new .py file;
2.reference Scrapy-master project(even I don't know how to do it);
3.write import in the new python file:
from scrapy.selector import Selector
from scrapy.http import HtmlResponse
4.the IDE report unresolved reference error(of cause):
and I don't know what to do to fix it.
Do I do the right thing ? Does it work?
In order to use/reference Scrapy in your project, your project's Python interpreter should be able to locate it. So install the Scrapy library and PyCharm will be able to load without an issue.
Install using Pycharm Package Management
You can install the package by going to File | Settings | Project Interpreter. Once there, follow the steps given in PyCharm Help Documentation
Install using Command Line
You can install Scrapy using Pip:
pip install scrapy
Or if you want to use your copy of the downloaded scrapy-master for any particular reason, change directory to scrapy-master and run:
python setup.py install
Ok now i will try to explain my problem as much as possible. I want to use popular compression algorithm 7zip at my c# project
There is already NuGet package for 7zip
Now when i install 7zip page https://www.nuget.org/packages/SevenZipSharp/0.64.0 it installs fine however it gives error when i try to run
An unhandled exception of type 'SevenZip.SevenZipLibraryException' occurred in SevenZipSharp.dll
Additional information: Can not load 7-zip library or internal COM error! Message: failed to load library
So i decide to add dll file manually and i get this error below
---------------------------
Microsoft Visual Studio
---------------------------
A reference to 'D:\51_doktora tez projesi\program_crawler\doktora_tez_projesi_crawler_program\ExternalDLLs\7z_9_38_2015_01_03.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
---------------------------
OK
---------------------------
Ok but i found a solution and it works that way
First install nuget package
And before start calling functions set path
SevenZip.SevenZipExtractor.SetLibraryPath("SevenZipSharp.dll");
SevenZip.SevenZipCompressor.SetLibraryPath("SevenZipSharp.dll");
Ok second question which is also interesting
I wanted to use latest version of 7zip DLL file. So downloaded it from official website : https://sourceforge.net/projects/sevenzip/files/7-Zip/9.38/
Downloaded MSI installed and got 64bit dll file. However when i try to reference this file, it fails with error message above: Please make sure that the file is accessible, and that it is a valid assembly or COM component.
However the trick works again
I install NuGet 7zip package. Then before calling functions i set these 2 lines of code and it uses latest version of DLL file
SevenZip.SevenZipExtractor.SetLibraryPath("ExternalDLLs/7z_9_38_2015_01_03.dll");
SevenZip.SevenZipCompressor.SetLibraryPath("ExternalDLLs/7z_9_38_2015_01_03.dll");
So i am looking for answers why all these happens? Why i can not directly add as a reference the DLL file however the trick works?
windows 8.1 64bit, Visual Studio 2013 update 3 WPF application
Part of your problem most likely stems from the fact that SevenZipSharp is merely a wrapper for the 7z.dll, which to the best of my knowledge is a c++ dll. The project page, for SevenZipSharp, also mentions that any compatible dll can be used and needs to be specified:
SevenZipSharp requires a 7-zip native library to function. You can specify the path to a 7-zip dll (7z.dll, 7za.dll, etc.) in LibraryManager.cs at compile time, your app.config or via SetLibraryPath() method at runtime. + "7z.dll" is the default path. For 64-bit systems, you must use the 64-bit versions of those libraries.
7-zip ships with 7z.dll, which is used for all archive operations (usually it is "Program Files\7-Zip\7z.dll"). 7za.dll is a light version of 7z.dll, it supports only 7zip archives. You may even build your own library with formats you want from 7-zip sources. SevenZipSharp will work with them all.
I downloaded Python for .NET.
Inside the zip is clr.pyd, nPython.exe, Python.Runtime.dll and 2 debug database files.
I put the clr.pyd and Python.Runtime.dll in my python DLLs dir C:\Python27\DLLs thinking this is all that's needed for installation. I then open up the Python GUI and type import clr and I get:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import clr
SystemError: dynamic module not initialized properly
New to python but not .NET and want to use the CPython and not IronPython. What am I missing in this installation? The readme of Python for .NET says there is an installation for Windows package but all I found was the zip file.
The proper way to load CLR in Python is like this:
Make sure no old stuff is left from Python.NET in Python installation folder (e.g. C:\Python27). In my case I had legacy clr.pyd in one of folders. Note that pip for some old versions did not remove all parts of Python.NET.
Append the directory with Python.NET files (clr.pyd and Python.Runtime.dll) to sys.path
Now you can load CLR the most flexible way without even installing to Python directories!
You can compile from source on github:
pip install git+https://github.com/pythonnet/pythonnet
or use Windows wheels/installers from Christoph Gohlke:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonnet
PyPI package is available for installation from pip:
https://pypi.python.org/pypi/pythonnet
More installation options such docker, WinPython, conda, nuget, choco are listed here:
https://github.com/pythonnet/pythonnet/wiki/Installation
The correct way to install Python for .NET is to copy ALL the files from the .zip into the directory that contains your .py file.
Then if you execute
python yourfilename.py
you should find that your "import clr" statement works. I have tested this using python 2.7 x86 and pythonnet-2.0-Beta0-clr4.0_140_py27_UCS2_x86.zip
I was able to replicate your error by only copying the clr.pyd file into my working directory.
Note that I was unable to make this work in Python 3.3 x86 or Python 3.3 x64
I actually took matters in to my own hands here and created a Python.Net Chocolatey package.
to install, simply run
cinst pythonnet
at the command line. Maybe this will help users having issues getting this to run.
I don't know why yet but the only way I could get it to work is to copy those 3 files into the C:\Python27\ directory directly.
If you are planning to freeze with py2exe or pyinstall be sure to install the dev version. There is something wrong with the 2.0.0 release when packaged with py2exe, pyinstaller and maybe other freezers. But 2.1.0.dev1 works well. So...
pip install --pre pythonnet
And you'll have to add the pythone.runtime.dll to the bundle (see docs for your preferred bundler).
There is also a problem with how py2exe loads the dll when using bundle_files: 1 (single exe).