Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line 399: Error message: "module 'bson' has no attribute 'BSON'" #547

Closed
rossmpowell opened this issue Oct 18, 2019 · 12 comments
Closed

Line 399: Error message: "module 'bson' has no attribute 'BSON'" #547

rossmpowell opened this issue Oct 18, 2019 · 12 comments

Comments

@rossmpowell
Copy link

Hi all,

I am working on a machine learning project, and using the Hyperas package to tune my model. Hyperas uses two functions to setup a tuning job: a data function, and model function. So far I've had some issues with them talking to each other during the encoding stage of building the model because the bson.BSON object called in hyperopt/base.py does not exist.

I ended up checking out the bson code found here: https://github.com/py-bson/bson, and the bson.BSON object does not exist there either. Is there a different bson distribution or package that I should be using?


Notes:

Thanks!

@rossmpowell
Copy link
Author

Update (Solution):

The sequence of imports below worked for getting bson a moment ago

pip install bson
pip install hyperopt
pip install hyperas
sudo pip uninstall bson
pip install pymongo

(Solution is similar to what was referenced in maxpumperla/hyperas#23)

@PhilipMay
Copy link
Contributor

I have the same problem (see below). Although there seems to be a workaround: can someone please fix this?

[...]
  File "/home/phmay/miniconda3/envs/tf2/lib/python3.6/site-packages/mltb/hyperopt.py", line 99, in fmin
    show_progressbar=show_progressbar,
  File "/home/phmay/miniconda3/envs/tf2/lib/python3.6/site-packages/hyperopt/fmin.py", line 403, in fmin
    show_progressbar=show_progressbar,
  File "/home/phmay/miniconda3/envs/tf2/lib/python3.6/site-packages/hyperopt/base.py", line 651, in fmin
    show_progressbar=show_progressbar)
  File "/home/phmay/miniconda3/envs/tf2/lib/python3.6/site-packages/hyperopt/fmin.py", line 422, in fmin
    rval.exhaust()
  File "/home/phmay/miniconda3/envs/tf2/lib/python3.6/site-packages/hyperopt/fmin.py", line 276, in exhaust
    self.run(self.max_evals - n_done, block_until_done=self.asynchronous)
  File "/home/phmay/miniconda3/envs/tf2/lib/python3.6/site-packages/hyperopt/fmin.py", line 225, in run
    self.trials.insert_trial_docs(new_trials)
  File "/home/phmay/miniconda3/envs/tf2/lib/python3.6/site-packages/hyperopt/base.py", line 435, in insert_trial_docs
    for doc in docs]
  File "/home/phmay/miniconda3/envs/tf2/lib/python3.6/site-packages/hyperopt/base.py", line 435, in <listcomp>
    for doc in docs]
  File "/home/phmay/miniconda3/envs/tf2/lib/python3.6/site-packages/hyperopt/base.py", line 399, in assert_valid_trial
    bson.BSON.encode(trial)
AttributeError: module 'bson' has no attribute 'BSON'

@rugg2
Copy link

rugg2 commented Oct 24, 2019

I am still having the issue AttributeError: module 'bson' has no attribute 'BSON'

when I type the code:

best_param = fmin(
        objective_function,
        param_hyperopt,
        algo=tpe.suggest,
        max_evals=3,
    )

I run on version hyperopt 0.2.1 from pypi, last released 2 days ago, which corresponds with the merge above. This is run inside a jupyter notebook locally on my machine (not sagemaker).

Has the fix been deployed @palicand ?

@palicand
Copy link
Contributor

@rugg2 As far as I can tell, it has not 0.2.1 has been released on 17. 10. 2019 based on releases here on GitHub, which is before the fix. I guess we need to ping @maxpumperla, as he seems to be the primary maintainer :-)

@maxpumperla
Copy link
Contributor

@palicand thanks for pinging me. I'll do another minor release for this in a bit.

@maxpumperla
Copy link
Contributor

@palicand and others, I didn't explicitly mention it here, but 0.2.2 has been up for a while and contains this fix.

@AwasthiMaddy
Copy link

AwasthiMaddy commented Dec 4, 2019

In 0.2.2 also, I am facing this same error.

AttributeError: module 'bson' has no attribute 'BSON

Not sure...if it is fixed!

@marctorsoc
Copy link
Member

I tried both in my mac and an AWS Ubuntu instance, both using a fresh conda env with python3.6. In both places after doing the

python setup.py develop &&  pip install -e '.[MongoTrials, SparkTrials, ATPE, dev]'

I could open a python terminal and run from bson import BSON. When I proposed my solution here #549 (comment) was having problems with another AWS Linux instance, but at least in the one I tried today it seems to work. Maybe a new version of bson is fixing this? 🤷‍♂️Can you try now in a fresh env @AwasthiMaddy

@marctorsoc
Copy link
Member

is this not a blocker anymore then @maxpumperla ?

@maxpumperla
Copy link
Contributor

@marctorrellas thanks, seems good after all.

@KIC
Copy link

KIC commented Mar 3, 2020

just installed 0.2.3 from pip having the same problem. However:

sudo -H pip uninstall bson
sudo -H pip install pymongo

solved the problem.

@marctorsoc
Copy link
Member

just installed 0.2.3 from pip having the same problem. However:

sudo -H pip uninstall bson
sudo -H pip install pymongo

solved the problem.

not sure those sudo are needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants