0

As with some other posts, I am running into a problem that, while operating in a virtual environment, python 3.6.5 does not recognize a package that I installed using pip (ImportError: No module named Levenshtein); e.g., here, here, and here. The package in question (python-Levenshtein 0.12.0) shows up when I call pip freeze and pip3 freeze in both the normal and virtual environments.

Following some of the answers given on the aforementioned pages, it looks like my problem results from the fact that more than one pathway to the Levenshtein package exists inside of the virtual environment. For reference:

python3 -m venv ~/.virtualenvs/myvenv
source ~/.virtualenvs/myvenv/bin/activate
python3
import sys, site
sys.prefix
'/Users/<home directory>/.virtualenvs/myvenv'
print(site.getsitepackages())
['/Users/<home directory>/.virtualenvs/myvenv/lib/python3.6/site-packages', '/Library/Python/3.6/site-packages']

So, I guess my question is two-fold:

  1. Is having more than one result for site.getsitepackages() the (likely) cause of the package not getting recognized in the virtual environment?
  2. If so, how do I remove the non-virtual environment path / reset the path for the virtual environment?

Thanks in advance for any help, really appreciated.

  • I don't think that's a correct analysis. You can create a venv without your system packages, but a bare venv which *only* contains system packages should behave identically to no venv. What actual problem are you experiencing, and where is the package(s) installed? Do you get a trackeback? – tripleee Sep 09 '20 at 13:47
  • Does `echo "$PYTHONPATH"` inside the venv print anything? What about outside? – tripleee Sep 09 '20 at 14:48
  • @tripleee Thanks for your responses, I apologize for being unclear – I am relatively new to Python and unfamiliar with diagnostic procedures and the virtual environment, generally. To answer your questions: 1) when attempting `import Levenshtein` in venv I got the traceback mentioned in the posts I linked to: `ImportError: No module named Levenshtein` 2) the 'echo "$PYTHONPATH"` call returns nothing both inside and outside venv. Although I'm not sure why, downloading the package inside venv with the % operator appears to solve the error: `%pip install python-Levenshtein` – user5671117 Sep 10 '20 at 14:37
  • Please [edit] your question to include these details. The `%` looks like you are using a notebook of some sort; probably provide information about that too. – tripleee Sep 10 '20 at 18:05

0 Answers0