'ModuleNotFoundError: No module named 'plotly' but it work from workspace

i have read all the posts related to this topic but i could not find the solution for my case.

In my ubuntu 20.04 I have installed plotly through the command:

pip3 install plotly

and if i launch python3 from command line and if i run:

import plotly.graph_objects as go

it works perfectly. But if i launch the same command from python script "test.py":

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import cgi
import cgitb
from datetime import date, timedelta
import datetime
import time
import numpy as np
import pandas as pd
import os
import calendar
import matplotlib
matplotlib.use('Agg')
import matplotlib.pylab as plt
import plotly.graph_objects as go

it returns the error log:

 ModuleNotFoundError: No module named 'plotly'

Anyone can help me? many thanks



Solution 1:[1]

Ok, i resolved the issue by installing the module as a root user because in this way Python will try to search for the module’s name in the root directory and not in the usr one

thank you everyone

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrea