Code Monkey home page Code Monkey logo

Comments (4)

belal-sweileh avatar belal-sweileh commented on July 22, 2024 1

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.

d99kris avatar d99kris commented on July 22, 2024

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.

d99kris avatar d99kris commented on July 22, 2024

Hi again,
I got a chance to try this out now. Here are the steps (tested on Windows 10, VS 2019 Community).

  1. Install Python from https://www.python.org/downloads/ and ensure python is added to PATH
  2. Open command prompt cmd.exe and run:
pip3 install -U spacy
python -m spacy download en_core_web_sm
  1. Open VS 2019, create a C++ "Console App" project.
  2. Download spacy-cpp from https://github.com/d99kris/spacy-cpp/archive/refs/heads/master.zip and extract the archive.
  3. Copy the folder spacy from spacy-cpp's src folder, to the VS project folder, ex: c:\Users\Kris\source\repos\SpacyTest\spacy
  4. Switch project target to "Release" and "x64".
  5. 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\
  1. 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";
}
  1. 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.

d99kris avatar d99kris commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.