Search code examples
pythonimportmodulepycharmattributeerror

Pycharm: Attribute Error


I have a project in Pycharm:

ProjectName (set as SourceRoot)

|_package1
  |- __init__.py
   -  package1.py
|_package2
  |- __init__.py
   - secondpythonfile.py 

The firstpythonfile.py contains the function placementfunction().

From secondpythonfile.py I want to call that function.

IN firstpythonfile.py:

  from package2 import secondpythonfile 

and

  secondpythonfile.placementfunction()

But Pycharm gives m the following error:

    AttributeError: module 'package2.secondpythonfile ' has no attribute 'placementfunction'

There appear to be a ton of Attribute Errors associated with PyCharm, but I am wondering whether there is some straight forward advice out there or someone who has dealt with this issue before?


Solution

  • Ok, I figured it out. Pycharm didn't like the fact that my package name 'package1' was the same as the file name package1.py inside. As soon as I changed it it worked.