0

my file directory is simple:

/Users/dd/python/folder/
   main.py
   store.py
   __init__.py
# store.py
class Store:
    def __init__(self,location):
        self.location = location

# main.py
from store import Store 
store = Store('Kansas')
print(store.location)

when I run main.py I get this error:

ImportError: cannot import name 'Store' from 'store' (/Users/dd/opt/anaconda3/lib/python3.9/store.py)

When I check sys.path I get a list that includes

  • /Users/dd/opt/anaconda3/lib/python3.9
  • /Users/dd/opt/anaconda3/lib/python3.9/site-packages
  • ...
  • /Users/dd/python/folder

From what I read in other questions if I add the path the way I did here at the end, it should work since the path list variable contains the local folder. Why does it ignore the local folder in this case?

Is it a problem with Anaconda?

I also couldn't find any examples of this error that included a path in parenthesis like this, where is that coming from?

I tried a virtual environment and that didn't change anything either. How can I set up python such that when I start a new folder the code operates from that folder?

user40551
  • 355
  • 4
  • 12
  • You can try this to create a namespace package. https://stackoverflow.com/questions/448271/what-is-init-py-for – ramsluk May 04 '23 at 12:49
  • I forgot to include that I had that file in the directory as well. I will edit the text of the question. – user40551 May 04 '23 at 12:54

1 Answers1

0

I managed to fix it by turning off the base conda environment, installing virtualenvs and creating a new virtualenv.

user40551
  • 355
  • 4
  • 12