I’m trying to import a package called spacy for NLP, but I keep getting this error:
Traceback (most recent call last):
File "/home/runner/Voice-Synthathizer-1/main.py", line 9, in <module>
import spacy
File "/home/runner/Voice-Synthathizer-1/venv/lib/python3.9/site-packages/spacy/__init__.py", line 6, in <module>
from .errors import setup_default_warnings
File "/home/runner/Voice-Synthathizer-1/venv/lib/python3.9/site-packages/spacy/errors.py", line 2, in <module>
from .compat import Literal
File "/home/runner/Voice-Synthathizer-1/venv/lib/python3.9/site-packages/spacy/compat.py", line 3, in <module>
from thinc.util import copy_array
File "/home/runner/Voice-Synthathizer-1/venv/lib/python3.9/site-packages/thinc/__init__.py", line 5, in <module>
from .config import registry
File "/home/runner/Voice-Synthathizer-1/venv/lib/python3.9/site-packages/thinc/config.py", line 2, in <module>
import confection
File "/home/runner/Voice-Synthathizer-1/venv/lib/python3.9/site-packages/confection/__init__.py", line 13, in <module>
import srsly
File "/home/runner/Voice-Synthathizer-1/venv/lib/python3.9/site-packages/srsly/__init__.py", line 1, in <module>
from ._json_api import read_json, read_gzip_json, write_json, write_gzip_json
File "/home/runner/Voice-Synthathizer-1/venv/lib/python3.9/site-packages/srsly/_json_api.py", line 6, in <module>
from . import ujson
File "/home/runner/Voice-Synthathizer-1/venv/lib/python3.9/site-packages/srsly/ujson/__init__.py", line 1, in <module>
from .ujson import decode, encode, dump, dumps, load, loads # noqa: F401
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory
I did some research on this and this is what I’ve tried:
I found out the issue, it was because I commented out the [interpreter] part of the .replit file.
This part add a very important part that was setting the LD_LIBRARY_PATH environment variable to python’s pre-defined library path.
That was causing the error in the first place (as packages did not know where they were located… correct me if I’m wrong)
The Solution
Obviously, you can just un-comment the interpreter part , BUT you can also just extract eny definition in the “env” part of the [interpreter.command] section into the [env] section instead. Like this:
# The command that runs the program. If the interpreter field is set, it will have priority and this run command will do nothing
run = "python3 main.py"
# The primary language of the repl. There can be others, though!
language = "python3"
entrypoint = "main.py"
# A list of globs that specify which files and directories should
# be hidden in the workspace.
hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"]
# Specifies which nix channel to use when building the environment.
[nix]
channel = "stable-21_11"
# The command to start the interpreter.
# [interpreter]
# [interpreter.command]
# args = [
# "stderred",
# "--",
# "prybar-python3",
# "-q",
# "--ps1",
# "\u0001\u001b[33m\u0002\u0001\u001b[00m\u0002 ",
# "-i",
# ]
[env]
# Fix Import issues /w some python packages
LD_LIBRARY_PATH = "$PYTHON_LD_LIBRARY_PATH"
VIRTUAL_ENV = "/home/runner/${REPL_SLUG}/venv"
PATH = "${VIRTUAL_ENV}/bin"
PYTHONPATH = "${VIRTUAL_ENV}/lib/python3.8/site-packages"
REPLIT_POETRY_PYPI_REPOSITORY = "https://package-proxy.replit.com/pypi/"
MPLBACKEND = "TkAgg"
POETRY_CACHE_DIR = "${HOME}/${REPL_SLUG}/.cache/pypoetry"
# Enable unit tests. This is only supported for a few languages.
[unitTest]
language = "python3"
# Add a debugger!
[debugger]
support = true
# How to start the debugger.
[debugger.interactive]
transport = "localhost:0"
startCommand = ["dap-python", "main.py"]
# How to communicate with the debugger.
[debugger.interactive.integratedAdapter]
dapTcpAddress = "localhost:0"
# How to tell the debugger to start a debugging session.
[debugger.interactive.initializeMessage]
command = "initialize"
type = "request"
[debugger.interactive.initializeMessage.arguments]
adapterID = "debugpy"
clientID = "replit"
clientName = "replit.com"
columnsStartAt1 = true
linesStartAt1 = true
locale = "en-us"
pathFormat = "path"
supportsInvalidatedEvent = true
supportsProgressReporting = true
supportsRunInTerminalRequest = true
supportsVariablePaging = true
supportsVariableType = true
# How to tell the debugger to start the debuggee application.
[debugger.interactive.launchMessage]
command = "attach"
type = "request"
[debugger.interactive.launchMessage.arguments]
logging = {}
# Configures the packager.
[packager]
language = "python3"
ignoredPackages = ["unit_tests"]
[packager.features]
enabledForHosting = false
# Enable searching packages from the sidebar.
packageSearch = true
# Enable guessing what packages are needed from the code.
guessImports = true
# These are the files that need to be preserved when this
# language template is used as the base language template
# for Python repos imported from GitHub
[gitHubImport]
requiredFiles = [".replit", "replit.nix", ".config", "venv"]
[languages]
[languages.python3]
pattern = "**/*.py"
[languages.python3.languageServer]
start = "pylsp"