Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named spacy. Try: pip install -U spacy #9

Closed
ZzoxAA opened this issue Jul 1, 2021 · 3 comments
Closed

No module named spacy. Try: pip install -U spacy #9

ZzoxAA opened this issue Jul 1, 2021 · 3 comments
Assignees

Comments

@ZzoxAA
Copy link

ZzoxAA commented Jul 1, 2021

I got this when I want to instantiate a Spacy object. But I'm sure I have installed spacy and I can run python -m spacy correctly. Cloud you please provide some possible reasons for this situation?

@d99kris
Copy link
Owner

d99kris commented Jul 9, 2021

Hi!
Let me first check, is the issue title exactly matching the error message you are seeing (older versions of spacy-cpp had such message, but recent versions suggests user to use pip3)? If yes, please try latest spacy-cpp.

Can your system access Spacy in Python? Like for example the Python code in https://github.com/d99kris/spacy-cpp#example-usage

If yes, I suspect there could be some mismatch between for which Python version Spacy is installed for, and which Python version you are building spacy-cpp for. By default spacy-cpp's CMakeLists.txt uses Python v3.x, so spacy needs to be installed for Python 3 (e.g. using pip3). Alternatively one can change spacy-cpp's CMakeLists.txt to build for Python 2 (not recommended as Python 2 is EOL) by changing:

find_package(PythonLibs 3 REQUIRED)
find_package(PythonInterp 3 REQUIRED)

to

find_package(PythonLibs 2.7 REQUIRED)
find_package(PythonInterp 2.7 REQUIRED)

and rebuild (maybe delete build dir first, just in case).

If still no success, perhaps you can share more system details such as version of OS, Python, CMake, C++ Compiler. Thanks!

@d99kris d99kris self-assigned this Jul 9, 2021
@d99kris
Copy link
Owner

d99kris commented Aug 10, 2021

I believe the above steps should help resolving the issue, so I will proceed to close this issue. Feel free to re-open it for follow-up questions. Thanks!

@d99kris d99kris closed this as completed Aug 10, 2021
@nuttyartist
Copy link

nuttyartist commented Feb 24, 2023

I'm getting the same error after building the header only example.

I'm running ./exprog1
And get:

libc++abi: terminating with uncaught exception of type std::runtime_error: No module named spacy. Try: pip3 install -U spacy
Abort trap: 6

EDIT: I can successfully reproduce the Python example usage:

>>> import spacy
>>> nlp = spacy.load("en_core_web_sm")
>>> doc = nlp(u"This is a sentence.")
>>> for token in doc:
...     print(token.text + " [" + token.pos_ + "]")
... 
This [PRON]
is [AUX]
a [DET]
sentence [NOUN]
. [PUNCT]

EDIT2:

Some more info - Cmake:

-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonLibs: /usr/local/Frameworks/Python.framework/Versions/3.11/lib/libpython3.11.dylib (found suitable version "3.11.0", minimum required is "3") 
-- Found PythonInterp: /Users/ruby/venv11_2/bin/python3 (found suitable version "3.11.1", minimum required is "3") 
-- Build tests: OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/build

Make:

[  7%] Building CXX object CMakeFiles/exprog1.dir/src/exprog1.cpp.o
In file included from /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/src/exprog1.cpp:5:
In file included from /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/spacy:12:
In file included from /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/attrs.h:72:
In file included from /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/attrs.cpp:13:
In file included from /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/python.h:210:
/Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/python.cpp:42:5: warning: 'PySys_SetArgv' is deprecated [-Wdeprecated-declarations]
    PySys_SetArgv(0, m_argv.get());
    ^
/usr/local/Frameworks/Python.framework/Versions/3.11/include/python3.11/sysmodule.h:13:1: note: 'PySys_SetArgv' has been explicitly marked deprecated here
Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
^
/usr/local/Frameworks/Python.framework/Versions/3.11/include/python3.11/pyport.h:336:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
1 warning generated.
[ 15%] Linking CXX executable exprog1
[ 15%] Built target exprog1
[ 23%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/attrs.cpp.o
[ 30%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/nlp.cpp.o
[ 38%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/python.cpp.o
/Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/python.cpp:42:5: warning: 'PySys_SetArgv' is deprecated [-Wdeprecated-declarations]
    PySys_SetArgv(0, m_argv.get());
    ^
/usr/local/Frameworks/Python.framework/Versions/3.11/include/python3.11/sysmodule.h:13:1: note: 'PySys_SetArgv' has been explicitly marked deprecated here
Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
^
/usr/local/Frameworks/Python.framework/Versions/3.11/include/python3.11/pyport.h:336:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
1 warning generated.
[ 46%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/span.cpp.o
[ 53%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/doc.cpp.o
[ 61%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/pyobjectptr.cpp.o
[ 69%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/spacy.cpp.o
[ 76%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/stringstore.cpp.o
[ 84%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/token.cpp.o
[ 92%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/vocab.cpp.o
[100%] Linking CXX shared library libspacy.dylib
[100%] Built target spacy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants