Comments (4)
Hi,
Thanks for your reply. I gave it a try, and it worked!
What steps would be needed to embed python and spacy into the C++ application so that it can be used on a machine without Python or Spacy installed and without the language model downloaded? Would I have to use an embeddable version of python on Windows for this and add the required python packages? Or perhaps freeze everything into an executable using PyInstaller? Please advise. Thanks.
from spacy-cpp.
Hi,
There's no Windows build available, nor any platform-specific steps for Windows.
If you're looking to just try the library out, I think using it as a header-only library should be fairly straight-forward, see
https://github.com/d99kris/spacy-cpp#header-only-library
You'll also need to install spaCy
and a model, something like this at the command prompt:
pip3 install -U spacy
python3 -m spacy download en_core_web_sm
I'm not sure if Visual Studio requires any special steps to find the python installation.
Perhaps you can try it out and see if it works? I don't have a Windows machine available right now, but I could maybe get a chance to try it out in the weekend.
from spacy-cpp.
Hi again,
I got a chance to try this out now. Here are the steps (tested on Windows 10, VS 2019 Community).
- Install Python from https://www.python.org/downloads/ and ensure python is added to PATH
- Open command prompt
cmd.exe
and run:
pip3 install -U spacy
python -m spacy download en_core_web_sm
- Open VS 2019, create a C++ "Console App" project.
- Download
spacy-cpp
from https://github.com/d99kris/spacy-cpp/archive/refs/heads/master.zip and extract the archive. - Copy the folder
spacy
fromspacy-cpp
'ssrc
folder, to the VS project folder, ex:c:\Users\Kris\source\repos\SpacyTest\spacy
- Switch project target to "Release" and "x64".
- Add Python include and libs paths to the project (adjust actual path depending on where Python was installed in step 1). Go to Project Properties -> Configuration Properties -> VC++ Directories. In
Include Directories
, add at the end:
;c:\Program Files\Python310\include\
In Library Directories
, add at the end:
;c:\Program Files\Python310\libs\
- Use the following code to test:
#include <iostream>
#define SPACY_HEADER_ONLY
#include "spacy/spacy"
int main()
{
Spacy::Spacy spacy;
auto nlp = spacy.load("en_core_web_sm");
auto doc = nlp.parse("This is a sentence.");
for (auto& token : doc.tokens())
std::cout << token.text() << " [" << token.pos_() << "]\n";
}
- Press F5 to build and run.
Will proceed to close this issue, but feel free to re-open for follow-up questions.
from spacy-cpp.
Hi again, sorry I don't know how to do that. I believe for Python itself one can probably distribute python.lib / libpython.so along with the executable (or link statically). But for Python packages (such as spacy
- and its models) I have no idea.
from spacy-cpp.
Related Issues (10)
- Is there a pure C wrapper? HOT 8
- Does this still build? HOT 5
- Is it possible to change the spaCy pipeline? HOT 3
- has NER support? HOT 1
- Adding this as a library in bazel is creating segmentation fault(core dumped) error HOT 3
- The connection between the two tokens is then established HOT 2
- Failed to build (Xcode) HOT 2
- Would iOS Support Be Possible? HOT 2
- No module named spacy. Try: pip install -U spacy HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spacy-cpp.