privML / privacy-evaluator

The privML Privacy Evaluator is a tool that assesses ML model's levels of privacy by running different attacks on it.
MIT License
17 stars 17 forks source link

Installing via setup.py #89

Closed Erdnaf closed 3 years ago

Erdnaf commented 3 years ago

I cant run the Notebook in the notebook folder.

With the help of @marisanest I installed a vitual environment based on python 3.9 and installed the Package with requirements.

But when I try to import the privacy_evaluator from the notebook i get this error:

ImportError                               Traceback (most recent call last)
<ipython-input-2-3baafc539e7e> in <module>
      5 #from privacy_evaluator.attacks.membership_inference.black_box_rule_based import MembershipInferenceBlackBoxRuleBasedAttack
      6 #from privacy_evaluator.attacks.membership_inference.label_only_decision_boundary import MembershipInferenceLabelOnlyDecisionBoundaryAttack
----> 7 import privacy_evaluator

~/.local/lib/python3.9/site-packages/privacy_evaluator/__init__.py in <module>
      2 The Privacy Evaluator.
      3 """
----> 4 from privacy_evaluator import attacks
      5 from privacy_evaluator import classifiers
      6 from privacy_evaluator import datasets

ImportError: cannot import name 'attacks' from partially initialized module 'privacy_evaluator' (most likely due to a circular import) (/home/claasfandre/.local/lib/python3.9/site-packages/privacy_evaluator/__init__.py)

How can i fix this?

I try to get it running maybe its because of python 3.9. but that schuldn't be the problem

marisanest commented 3 years ago

Ok, this issue really seems to be a bug in Python 3.9: https://discuss.python.org/t/differences-between-3-8-and-3-9-in-importing-module/5520. It was solved on 2021-03-20, so if you install again the newest Python 3.9 version or a lower version (e.g. 3.8) it should work.

jtorhoff commented 3 years ago

Can confirm that it works now. Updated from 3.9.4 to 3.9.5 and see no import issues anymore. Works without virtualenv too.

blauertee commented 3 years ago

Does not work on python 3.9.5 for me


Python 3.9.5 (default, May 19 2021, 11:32:47) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
->>> import privacy_evaluator
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jakob/Downloads/privML/env/lib/python3.9/site-packages/privacy_evaluator/__init__.py", line 4, in <module>
    from privacy_evaluator import attacks
ImportError: cannot import name 'attacks' from partially initialized module 'privacy_evaluator' (most likely due to a circular import) (/home/jakob/Downloads/privML/env/lib/python3.9/site-packages/privacy_evaluator/__init__.py)```
blauertee commented 3 years ago

Hey @adrinjalali do you know what we're might be doing wrong here?

jtorhoff commented 3 years ago

Strangely enough the notebook doesn't work for me now. I did a fresh install:

$ pip uninstall privacy_evaluator
$ git clone git@github.com:privML/privacy-evaluator.git
$ cd privacy-evaluator
$ pip install .
$ python3
>>> from privacy_evaluator.models.torch import dcti
>>> model = dcti.load_dcti()
>>> model

Should show the summary of the model. It might be possible, however, that some imports don't work but you can try the above and see if it works.

Just did the above now and it works. Python version summary:

Python 3.9.5 (default, May  4 2021, 03:33:11) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
jtorhoff commented 3 years ago

import privacy_evaluator doesn't work for me if I run python3 outside of privacy-evaluator directory, so we definitely have a problem here.

adrinjalali commented 3 years ago

Have you tried relative imports and setting the __all__ attribute in your __init__ files, including the one in attack module? It seems your imports are causing a circular import path.

marisanest commented 3 years ago

I think we solved this issue so I close it.