Search code examples
pythonvisual-studio-codebottlepipenv

Unable to import a package in Python


I am new to Python Development and I tried to create a very simple API using Bottle Web Framework. And I got the following error: "Unable to import 'bottle'pylint(import-error)".

I am using Python 3.8.6 with pipenv.

The commands I runned were the following:

pipenv shell

pipenv install bottle

The code in the main.py file is as follows:

from bottle import get, run

@get('/')
def index():
    return 'Hello World'

run(host='localhost', port=7819)

To run the main.py file, use the following command:

python3 main.py

But the previous command only works if I have the work environment running (pipenv shell).

I tried to disable the Python Linting (which I didn't want to do because it helps us) and I changed the interpreter several times.

And the error I always have is this:

Traceback (most recent call last):

File "main.py", line 1, in <module>

from bottle import get, run

ModuleNotFoundError: No module named 'bottle'

I don't know if it has anything to do with it but I installed pipenv with HomeBrew and Pylint was installed as an VS Code extension.

Thank you guys, I am just tired of trying so many different solutions and the error persists. 😞


Solution

  • find the script file open cmd and change directory to your script and run pip install bottle. and pip install shell It worked for me