简体   繁体   中英

How to make 2 versions of Fasttext Python wrapper work together?

We have used Facebook's Fasttext amazing library for a while. We access the trained models using the python wrapper ( https://pypi.org/project/fasttext/ ). It used to be a third-party library, but is now maintained by Facebook and was merged to their repository .

The problem is that the two wrappers are not compatible. The old one is imported via import fasttext (lowercased) and the new one - via import fastText . The API is also somewhat different. But most importantly, the new library doesn't support the models trained by older Fasttext versions, whereas the old one does support them, but doesn't support the newly trained ones.

We're planning to migrate all our models to the new Fasttext version (it has quantization and is supposedly faster), but it takes time during which we need to support both types of models. So we need the both wrappers working side by side.

The problem with installing them together is that, despite the different module names, they try to get installed in the same directories by pip ( fasttext ). So one of them overwrites the other.

How to make them work side by side? Preferably within the same install prefix directory.

The most reliable approach across platforms is to install one globally and the other as user:

pip install git+https://github.com/facebookresearch/fastText.git
pip install --user fasttext

The only way that seems to work is exactly this installation order:

pip install git+https://github.com/facebookresearch/fastText.git
pip install -I fasttext

First install the new version, and then the old one. -I flag tells pip to reinstall packages, even if they're already installed. Otherwise pip finds the new version and doesn't want to install the old one (even though they actually get installed to different directories). After this, both versions seem to co-exist happily:

python -c "import fasttext; print fasttext.__file__"
local/lib/python2.7/site-packages/fasttext/__init__.pyc
python -c "import fastText; print fastText.__file__"
local/lib/python2.7/site-packages/fastText/__init__.pyc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM