Jurdun
Jurdun

Reputation: 145

Why doesn't import work for me? - Python

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

Answers (2)

Sibeesh Venu
Sibeesh Venu

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.

enter image description here

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.

enter image description here

Now it will take the modules from your virtual environment.

Upvotes: 0

Martijn Pieters
Martijn Pieters

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

Related Questions