Forums

ModuleNotFoundError: No module named 'backtrader'

I am unable to import backtrader. I have installed backtrader using "pip install backtrader". The package has installed correctly for Python 3.7 version. virtualenv is also correctly configured along with the webapp. plz assit.

import backtrader as bt "ModuleNotFoundError: No module named 'backtrader'"

Have you reloaded your web app since you installed the module?

yes. i have reloaded. also tried pip3.7 install --user backtrader

FYI: last week my code was working correctly with backtrader (on a diff virtual env which i have now deleted)

you have my permission to check/run my python file bt_screener.py

Are you sure that backtrader is what you're supposed to be importing? There are packages on PyPI where the name of the module that you import is different to the package name that you install.

yes its backtrader. I am able to run the same code on my local system , also as i said earlier the code was able to import last week

Found a hack.

import sys

sys.path.append("/home/rizwan236z/.virtualenvs/FARBT/lib/python3.7/site-packages/")

import backtrader as bt

If that worked, then you probably had just not activated the virtualenv where you were running the code that failed to import.

Hi Glenn,

I believe I am having a similar issue. I have a cloud_functions.py file with functions in it for download/uploading data to Google Cloud. This works well and is used through my website.

However, I have another auto_updater.py file in the same folder with the others which I am trying to set as a task to run daily. This auto_updater.py file uses functions from cloud_functions.py. However I am getting errors that when the task auto_updater.py is running that the cloud_functions.py script is then unable to import modules which it normally has no problems with during normal use on the website.

Is this because files running as tasks are not in the normal virtualenv? I can confirm that the task, the website, and all modules are using the same python version.

Thank you for your help Glenn

We have a help page on how to use virtual environments in scheduled tasks.

Thank you pafk! That worked perfectly!

Glad to hear that!