oracle/oci-python-sdk

oci module component is treated as a dictionary object

aureliocirella opened this issue · 5 comments

Hi,
I'm using oci (2.112.1) and suddenly python does not recognize oci.config as a module anymore, but it is considered as a dictionary, as shown below:

Traceback (most recent call last):
  File "oci.py", line 3, in <module>
    config = oci.config.from_file(profile_name="PROFILE_NAME")
AttributeError: 'dict' object has no attribute 'from_file'

My code looks like this:

import oci
config = oci.config.from_file(profile_name="PROFILE_NAME")

The same error appears both when using system wide python/pip executables and virtual environments.

My setup:

  • Windows 11 Pro
  • WSL 2.0.9.0
  • Ubuntu 20.04.6 LTS
  • Python 3.8.10
  • oci 2.112.1

Any help is appreciated, thanks in advance.

Hi @aureliocirella I do not see that we made this change. Was this code working before and it stopped working ?

Can you try importing like this. This is working for us.

from oci.config import from_file
oci_config = from_file(file_location="~/.oci/config", profile_name="DEFAULT")

Hi, exactly. The problem came up suddenly, in the previous days it was working correctly.

Here's my code:

import oci
from oci.config import from_file
config = from_file(profile_name="PROFILE")

But I get the error:

Traceback (most recent call last):
  File "compartment-explorer.py", line 2, in <module>
    from oci.config import from_file
ModuleNotFoundError: No module named 'oci.config'; 'oci' is not a package

This is the output of pip3 list:

pip3 list | grep oci           
oci                2.112.1

Let me know if I can provide further proof.

Thank you.

@aureliocirella Are you running your script inside virtualenv ? It looks like the error this time is different. It's not even recognizing 'oci' as a package. I would guess there is something wrong how the oci is installed and setup.

I'm trying both from virtualenv and system wide libraries.
I've tried several times installing the OCI package from a local folder (downloading it from Github) but without success.

Other Python packages are working fine. Hence I don't think that my Python installation/libraries are corrupted.
In your knowledge, is there a way to check if the OCI package has been installed correctly? And what is the package that get imported?

As suspected, Python wasn't importing the module correctly. That is because I had a file in my working directory called "oci.py".
I discovered which module python was importing by print(oci).

Renaming that file made oci module being correctly imported again.

Thanks for the help and sorry for the inconvenience.