0

I'm trying to import autograd with the following line of code:

import autograd.numpy as np

However, I'm getting the following error when trying to run the script:

Traceback (most recent call last):
  File "autograd.py", line 1, in <module>
    import autograd.numpy as np
  File "/home/hakon/Documents/FYS_STK4155/project2/code and plots/test/autograd.py", line 1, in <module>
    import autograd.numpy as np
ModuleNotFoundError: No module named 'autograd.numpy'; 'autograd' is not a package

I've tried installing autograd through pip, pip3 and conda, but the error remains the same.

aaossa
  • 3,763
  • 2
  • 21
  • 34
  • 1
    Does this answer your question? [Python 'No module named' error; 'package' is not a package](https://stackoverflow.com/questions/54333865/python-no-module-named-error-package-is-not-a-package) – Gino Mempin Feb 20 '22 at 01:43

2 Answers2

0

The problem is that your module (the one that you're running) has the same name that you're trying to import: autograd (.py). Try renaming your file and running it again.

aaossa
  • 3,763
  • 2
  • 21
  • 34
0

aaossa's answer worked for me. If changing the module name that you are running doesn't work, please check if there is any other autograd(.py) that you created existing in your current directory. If so, you also need to change that file's name or delete it so that you can import "autograd".

OmerE
  • 1
  • 1
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31319527) – gremur Mar 21 '22 at 18:44