Reputation: 145
Whenever I try to import a file into python, it comes up with this error(or similar):
Traceback (most recent call last):
File "C:/Python33/My Files/username save.py", line 1, in <module>
import keyring.py
ImportError: No module named 'keyring'
I am trying to create a password storing program, and I was looking up for good ways to keep passwords secure, and someone said use import keyring, so I did, except, it never works. I must be doing something wrong, but whenever I look anything up for python, it never works out for me. It's almost as if loads have things have been changed over the years.
and idea's?
Upvotes: 2
Views: 8861
Reputation: 21719
I was getting the same error "ModuleNotFoundError: No module named 'keyring'". And after installing this module pip install keyring
, the same error occured with another module name. Then I came to the conclusion that it is the fact that the VSCode is not able to connect to my venv
, even after setting the Python Itereptor
. Press CTRL + SHIFT + P, and then type Python: Select Interceptor, and select your venv, if you want to set this.
To fix the issue, I had to force the VSCode to use the .venv
I created, and luckily there is a dropdown to do that, on the top right corner as in the preceeding image. Click ont the Python version, and then you will be able to select your virtual environment.
Now it will take the modules from your virtual environment.
Upvotes: 0
Reputation: 1121564
The keyring
module is not part of the Python standard library. You need to install it first. Installation instructions are included.
Once installed, use import keyring
, not import keyring.py
; the latter means import the py
module from the keyring
package. Python imports should use just the name of the module, so not the filename with extension. Python can import code from more than just .py
python files.
Upvotes: 11