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

Colab import pyepo error #45

Closed
ZedongPeng opened this issue Nov 18, 2024 · 1 comment
Closed

Colab import pyepo error #45

ZedongPeng opened this issue Nov 18, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@ZedongPeng
Copy link

I attempted to run the jupyter-notebook example using Colab, but encountered an error during import pyepo. Could you please advise on how to resolve this issue?

Thank you in advance!

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-16-9aebf8cb754e>](https://localhost:8080/#) in <cell line: 3>()
      1 import time
      2 import random
----> 3 import pyepo
      4 import torch
      5 from torch import nn

6 frames
[/usr/local/lib/python3.10/dist-packages/pyomo/common/dependencies.py](https://localhost:8080/#) in find_spec(self, fullname, path, target)
    525         # the module is coming from: file system, registry, etc.)
    526         for finder in sys.meta_path[sys.meta_path.index(self) + 1 :]:
--> 527             spec = finder.find_spec(fullname, path, target)
    528             if spec is not None:
    529                 break

AttributeError: '_PyDrive2ImportHook' object has no attribute 'find_spec'
@LucasBoTang LucasBoTang pinned this issue Dec 8, 2024
@LucasBoTang
Copy link
Collaborator

We’re aware that this issue stems from environmental hooks in Colab. While this is not directly a pyepo bug, we’ll consider doing something to help users who run into this. We will also keep an eye on changes to pyomo or PyDrive2 that might address the underlying incompatibility.

The error seems to be caused by a compatibility conflict between pyomo (a dependency of pyepo) and the PyDrive2 import hook in the Google Colab environment.

Google Colab sets up some custom import hooks such as (_PyDrive2ImportHook) to integrate with Google Drive. Still, this hook does not implement find_spec as expected by Python’s newer import machinery, which pyomo relies on.

You can temporarily remove the problematic hook with:

import sys
sys.meta_path = [hook for hook in sys.meta_path if not any(keyword in str(hook) for keyword in ["google.colab"])]

Thank you for your patience, and please let us know if you have any further difficulties.

@LucasBoTang LucasBoTang reopened this Dec 8, 2024
@LucasBoTang LucasBoTang added the help wanted Extra attention is needed label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants