tongshuangwu / polyjuice

BSD 3-Clause "New" or "Revised" License
96 stars 17 forks source link

ImportError: cannot import name 'Polyjuice' from 'polyjuice' (unknown location) #4

Closed EoinKenny closed 3 years ago

EoinKenny commented 3 years ago

Hi thanks for the repo.

I've been trying for a while to get the library working but with no success, I'm fairly sure I haven't done anything wrong on my end but I could be wrong.

I use these commands:

python3 -m venv polyjuice
source polyjuice/bin/activate
pip install polyjuice_nlp
python
import polyjuice

Then when using it I always get the above error. I also tried cloning from the repo etc and nothing is working. I even asked other people on other computers to try and it always fails. Any suggestions? Thank you. I'm interested in generating counterfactual NLP explanations with this.

tongshuangwu commented 3 years ago

~hi! Could you please also copy the error message here?~

Edit: Sorry I totally missed the title on my first read.

Could you please try to use a different virtualenv name? e.g.

python3 -m venv polyjuice_env
source polyjuice_env/bin/activate
pip install polyjuice_nlp
python
from polyjuice import Polyjuice

My guess is, because the venv has the same name as the package, it confuses python as to what "polyjuice" we are importing.

EoinKenny commented 3 years ago

Hi again, thanks a lot for the quick response!

I ran the commands exactly as you instructed, but it still doesn't work. I will post the entire terminal output from after the "pip install polyjuice_nlp" part. I seems to be something to do with mysql?

Collecting polyjuice_nlp
  Using cached https://files.pythonhosted.org/packages/1a/9a/cacff55c0f39529f08837c255b7cf0b67eaedd6c6c9641ea483027ac5799/polyjuice_nlp-0.1.4.tar.gz
Collecting munch>=2.5.0 (from polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/cc/ab/85d8da5c9a45e072301beb37ad7f833cd344e04c817d97e0cc75681d248f/munch-2.5.0-py2.py3-none-any.whl
Collecting spacy>=3.0.6 (from polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/50/84/35db41e9fb0c2ec6daeab144cd88b747342bd462bc4850d7f82a972089b5/spacy-3.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting scipy (from polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/5a/00/0569c9566c8d758af25cb3b70af68b28df5c6d549d78135ac127edfb581e/scipy-1.7.0-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting sentence-transformers>=1.1.0 (from polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/3b/fd/8a81047bbd9fa134a3f27e12937d2a487bd49d353a038916a5d7ed4e5543/sentence-transformers-2.0.0.tar.gz
Collecting transformers>=4.5.1 (from polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/fd/1a/41c644c963249fd7f3836d926afa1e3f1cc234a1c40d80c5f03ad8f6f1b2/transformers-4.8.2-py3-none-any.whl
Collecting pattern>=3.6.0 (from polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/1e/07/b0e61b6c818ed4b6145fe01d1c341223aa6cfbc3928538ad1f2b890924a3/Pattern-3.6.0.tar.gz
Collecting nltk (from polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/5e/37/9532ddd4b1bbb619333d5708aaad9bf1742f051a664c3c6fa6632a105fd8/nltk-3.6.2-py3-none-any.whl
Collecting zss (from polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/1e/d1/ed34d12f55d07cc1efb61d74fb2f64f46a705557f5bdd1ef1b810f0e2ec5/zss-1.2.0.tar.gz
Collecting six (from munch>=2.5.0->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl
Collecting wasabi<1.1.0,>=0.8.1 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/a6/1d/d281571b4c3b20fff183b485c6673c62878727119a849c7932651a8b5060/wasabi-0.8.2-py3-none-any.whl
Collecting packaging>=20.0 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/3c/77/e2362b676dc5008d81be423070dd9577fa03be5da2ba1105811900fda546/packaging-21.0-py3-none-any.whl
Collecting tqdm<5.0.0,>=4.38.0 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/7a/ec/f8ff3ccfc4e59ce619a66a0bf29dc3b49c2e8c07de29d572e191c006eaa2/tqdm-4.61.2-py2.py3-none-any.whl
Collecting numpy>=1.15.0 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/49/d2/057683bbe4f8cccbd74f9b98dee5b1c5b94c06c115790d4bb50ec31aab77/numpy-1.21.1-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting catalogue<2.1.0,>=2.0.4 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/9c/10/dbc1203a4b1367c7b02fddf08cb2981d9aa3e688d398f587cea0ab9e3bec/catalogue-2.0.4-py3-none-any.whl
Collecting srsly<3.0.0,>=2.4.1 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/ff/95/acde60d539724a1580644e3aad295b78ba01487767149399d93ee9d6078e/srsly-2.4.1-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting spacy-legacy<3.1.0,>=3.0.7 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/d3/e8/1bc00eeff3faf1c50bde941f88a491a5c1128debb75dd8c913401e71585c/spacy_legacy-3.0.8-py2.py3-none-any.whl
Collecting pydantic!=1.8,!=1.8.1,<1.9.0,>=1.7.4 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/12/b7/825bf1578e5bd4e70813f40f8e10c11c7ddcf0e0a59faefa79c65b37a139/pydantic-1.8.2-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting pathy>=0.3.5 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/65/ae/ecfa3e2dc267010fa320034be0eb3a8e683dc98dae7e70f92b41605b4d35/pathy-0.6.0-py3-none-any.whl
Collecting typer<0.4.0,>=0.3.0 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/90/34/d138832f6945432c638f32137e6c79a3b682f06a63c488dcfaca6b166c64/typer-0.3.2-py3-none-any.whl
Collecting thinc<8.1.0,>=8.0.7 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/13/66/b4017fd5d8b13d88da103418c741fb586c9dd0d7f608978b0bccad5c6523/thinc-8.0.8-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting requests<3.0.0,>=2.13.0 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/92/96/144f70b972a9c0eabbd4391ef93ccd49d0f2747f4f6a2a2738e99e5adc65/requests-2.26.0-py2.py3-none-any.whl
Collecting blis<0.8.0,>=0.4.0 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/5c/f2/c0bd2de42c442fe1e0826aa525f9a8037b37eda465dbe09e9d7edbfb2f15/blis-0.7.4-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting jinja2 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/80/21/ae597efc7ed8caaa43fb35062288baaf99a7d43ff0cf66452ddf47604ee6/Jinja2-3.0.1-py3-none-any.whl
Collecting cymem<2.1.0,>=2.0.2 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/f5/e4/270d7d5b64528480f6f9923325266486ab286c014ce83610d7bc43368218/cymem-2.0.5-cp37-cp37m-macosx_10_9_x86_64.whl
Requirement already satisfied: setuptools in ./polyjuice_env/lib/python3.7/site-packages (from spacy>=3.0.6->polyjuice_nlp) (40.8.0)
Collecting typing-extensions<4.0.0.0,>=3.7.4; python_version < "3.8" (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/2e/35/6c4fff5ab443b57116cb1aad46421fb719bed2825664e8fe77d66d99bcbc/typing_extensions-3.10.0.0-py3-none-any.whl
Collecting murmurhash<1.1.0,>=0.28.0 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/17/34/5abf7fcb3085dc7ad752af9a9b517d739ce62d16061f97cdda7bce0b53fc/murmurhash-1.0.5-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting preshed<3.1.0,>=3.0.2 (from spacy>=3.0.6->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/f2/10/f18af885d80d458eaa25732348f70dbb1b83d24fa49a9fb5fee963f24def/preshed-3.0.5-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting torch>=1.6.0 (from sentence-transformers>=1.1.0->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/51/cd/3fa53975000c37b0a0e4f5db7dd2df45749bfbc5f04c5b99812df6794511/torch-1.9.0-cp37-none-macosx_10_9_x86_64.whl
Collecting torchvision (from sentence-transformers>=1.1.0->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/cd/ba/00f5e77bc094be01f69b1906b208b58018dcbd5d3f5c4524f0e584dcb323/torchvision-0.10.0-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting scikit-learn (from sentence-transformers>=1.1.0->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/04/79/306714443069278702eaf767e82c0a619d7e93119fa9d7b075ccc7dd4801/scikit_learn-0.24.2-cp37-cp37m-macosx_10_13_x86_64.whl
Collecting sentencepiece (from sentence-transformers>=1.1.0->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/18/b4/61c100a53fa950fda87a8b9cd16ff7e9b8f41b9e47e6bd5e7775288cf742/sentencepiece-0.1.96-cp37-cp37m-macosx_10_6_x86_64.whl
Collecting huggingface-hub (from sentence-transformers>=1.1.0->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/67/d5/07894f2f047055576c3559a66d921c37d1280fda74b08fe574a8490e5999/huggingface_hub-0.0.14-py3-none-any.whl
Collecting sacremoses (from transformers>=4.5.1->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/75/ee/67241dc87f266093c533a2d4d3d69438e57d7a90abb216fa076e7d475d4a/sacremoses-0.0.45-py3-none-any.whl
Collecting importlib-metadata; python_version < "3.8" (from transformers>=4.5.1->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/3f/e1/e5bba549a033adf77448699a34ecafc7a32adaeeb4369396b35f56d5cc3e/importlib_metadata-4.6.1-py3-none-any.whl
Collecting tokenizers<0.11,>=0.10.1 (from transformers>=4.5.1->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/6b/f5/e77aa6e8a95ce260d83f99fc88f57844e24d52dc35e7db287debe08b4149/tokenizers-0.10.3-cp37-cp37m-macosx_10_11_x86_64.whl
Collecting filelock (from transformers>=4.5.1->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/93/83/71a2ee6158bb9f39a90c0dea1637f81d5eef866e188e1971a1b1ab01a35a/filelock-3.0.12-py3-none-any.whl
Collecting regex!=2019.12.17 (from transformers>=4.5.1->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/64/b8/c61c8f3445f47ff43af069357e803b5e770c3dcc36d14a8bc0215d920bb4/regex-2021.7.6-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting pyyaml (from transformers>=4.5.1->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/6b/8c/674cc47282af12bd7f12eea6cc87d907ada593b15f5ba0b51638599500c9/PyYAML-5.4.1-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting future (from pattern>=3.6.0->polyjuice_nlp)
Collecting backports.csv (from pattern>=3.6.0->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/8e/26/a6bd68f13e0f38fbb643d6e497fc3462be83a0b6c4d43425c78bb51a7291/backports.csv-1.0.7-py2.py3-none-any.whl
Collecting mysqlclient (from pattern>=3.6.0->polyjuice_nlp)
  Using cached https://files.pythonhosted.org/packages/3c/df/59cd2fa5e48d0804d213bdcb1acb4d08c403b61c7ff7ed4dd4a6a2deb3f7/mysqlclient-2.0.3.tar.gz
    Complete output from command python setup.py egg_info:
    /bin/sh: mysql_config: command not found
    /bin/sh: mariadb_config: command not found
    /bin/sh: mysql_config: command not found
    mysql_config --version
    mariadb_config --version
    mysql_config --libs
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/t9/66yl1p5n6mv6j78yrkn6bfgw0000gq/T/pip-install-426wyd09/mysqlclient/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "/private/var/folders/t9/66yl1p5n6mv6j78yrkn6bfgw0000gq/T/pip-install-426wyd09/mysqlclient/setup_posix.py", line 70, in get_config
        libs = mysql_config("libs")
      File "/private/var/folders/t9/66yl1p5n6mv6j78yrkn6bfgw0000gq/T/pip-install-426wyd09/mysqlclient/setup_posix.py", line 31, in mysql_config
        raise OSError("{} not found".format(_mysql_config_path))
    OSError: mysql_config not found

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/t9/66yl1p5n6mv6j78yrkn6bfgw0000gq/T/pip-install-426wyd09/mysqlclient/
You are using pip version 19.0.3, however version 21.1.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(polyjuice_env) ➜  test_agreement_vgg16 python
Python 3.7.4 (default, Aug 13 2019, 15:17:50) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from polyjuice import Polyjuice
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'polyjuice'
>>> 

I also tried to upgrade pip, but that didn't work either.

tongshuangwu commented 3 years ago

Ah, now it seems like a different error from one of the dependencies we use (pattern.en). Could you please take a look at this and this?

EoinKenny commented 3 years ago

Thanks again.

The first link really helped me, by running

python3 -m venv env
source env/bin/activate
brew install mysql
pip install mysqlclient
pip install polyjuice_nlp

It does install successfully! Doing a "pip list" you can see polyjuice installed, alongside pattern etc... and all the libraries import successfully, except for polyjuice.

image

So, this works, it installs, but for some reason polyjuice is the only library I can't import in the environment then unfortunately.

Here's a screenshot of the versions installed if that helps. Screenshot 2021-07-21 at 11 10 42

tongshuangwu commented 3 years ago

Sorry, my bad, I've fixed the error in setup.py (which was causing the problem in venv) in https://github.com/tongshuangwu/polyjuice/commit/f7db3494642feeeae70f256998943cad0a363c79 if you install pip install polyjuice==0.1.5, hopefully it will work...

EoinKenny commented 3 years ago

No problem!

So, I can install pip install polyjuice==0.1.0 and you can run import polyjuice no problem.

But if I run pip install polyjuice==0.1.5 it gives this error

image

Thanks again for the help!

tongshuangwu commented 3 years ago

Oops, please change the name to polyjuice_nlp :)

On Fri, Jul 23, 2021 at 1:57 AM Eoin Kenny @.***> wrote:

No problem!

So, I can install pip install polyjuice==0.1.0 and you can run import polyjuice no problem.

But if I run pip install polyjuice==0.1.5 it gives this error

[image: image] https://user-images.githubusercontent.com/22933434/126759482-dd365c5a-1b73-416e-9f2d-2fd611c6b989.png

Thanks again for the help!

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/tongshuangwu/polyjuice/issues/4#issuecomment-885498157, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRSLKZPVP74ZCEO3R3OQK3TZEVGTANCNFSM5ATYGXCQ .

-- Best, Sherry

EoinKenny commented 3 years ago

Nice, it works!

tongshuangwu commented 3 years ago

perfect! Sorry it took so many rounds. Please let me know if you still run into errors!

EoinKenny commented 2 years ago

Hi again, I'm reopening because if I run this

image

I'm getting the following problem

image

EoinKenny commented 2 years ago

@tongshuangwu Sorry I don't know if you get updates on dead threads so I'm just tagging you here :-)