Search code examples
pythonvisual-studio-codeimporterror

Cannot import installed package


I was following the Packaging Python projects tutorial and everything was working fine. I uploaded my package to pypi and I can install it. However upon importing, something odd happens;
Inside the shell, it works fine.

>>> import noodle_extensions
>>> # no errors indicate that it was imported properly.
>>> print(noodle_extensions)
<module 'noodle_extensions' from 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\noodle_extensions\\__init__.py'>

However, inside VScode, I get this;

import noodle_extensions
Traceback (most recent call last):
  File "c:/Users/user/OneDrive/Desktop/Codes/Python/Tests/test.py", line 1, in <module>
    import noodle_extensions
ModuleNotFoundError: No module named 'noodle_extensions'

control+clicking it does not work. pylint thinks that it doesn't exist.
In terms of files at the pip install location, I have the noodle_extensions containing the __init__.py, the .egg-info folder and a .dist-info folder.
Is there something I can do?
PyPi site


Solution

  • According to your description, the module "noodle_extensions" exists in the environment "Python3.9", please click on the Python interpreter displayed in the lower left corner of VSCode (or use F1, python: Select Interpreter), and then select "Python3.9":

    enter image description here

    Or reinstall the module "noodle_extensions" in the currently selected "Python3.8" environment.

    Check the installation package:

    enter image description here

    Reference: Environment in VSCode.