Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 429
Jurdun Avatar asked Jun 08 '26 13:06

Jurdun


2 Answers

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.

like image 103
Martijn Pieters Avatar answered Jun 11 '26 03:06

Martijn Pieters


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.

like image 37
Sibeesh Venu Avatar answered Jun 11 '26 02:06

Sibeesh Venu